<commit_before># coding: utf-8
import datetime
import time
import json
import flask
import requests
from flask import request, flash, redirect, url_for, render_template

import models

bp = flask.Blueprint('home', __name__)

@bp.route('/ruok', methods=['GET', 'POST'])
def ruok():
    return 'imok'

def cleanname(name):
    for prefix in 'http://', 'https://', '/':
        if name.startswith(prefix):
            name = name[len(prefix):]
    for suffix in '/', '.git':
        if name.endswith(suffix):
            name = name[:-len(suffix)]
    name = name.replace(':', '/')
    return name

def checkrepo(name):
    ''' return desc '''
    payload = {'pkgname': name}
    requests.get('https://gowalker.org/'+name) # call gowalker to load data
    r = requests.get('https://gowalker.org/api/v1/pkginfo', params=payload)
    d = r.json()
    if not d['id']:
        raise Exception('error load package in https://gowalker.org: %s' % r.text)

    if not d['cmd']:
        raise Exception('Repo: [%s] is a go-lib, this platform only support main package' % name)
    return d['synopsis']

@bp.route('/')
@models.db_session
def home():
    address = flask.request.args.get('address')
    if address:
        reponame = cleanname(address)
        if not models.Repo.get(name=reponame):
            try:
                nocheck = 'nocheck-'
                if reponame.startswith(nocheck):
                    reponame = reponame[len(nocheck):]
                    desc = 'unknown desc'
                else:
                    desc = checkrepo(reponame)
            except Exception as e:
                force_add = '''If you confirm this is a go main package. Click <a class="btn btn-warning btn-xs" href="/address=nocheck-%s">force add</a>''' %(reponame)
                error = str(e) + ' <br>- ' + force_add
                return flask.render_template('index.html', error=flask.Markup(error))
            repo = models.Repo(name=reponame)
            repo.created = datetime.datetime.today()
            repo.description = desc
            repo.author = 'unknown .. unfinished'
            models.commit()

        return flask.redirect('/'+reponame, 302)

    new = models.select(r for r in models.Repo).\
            order_by(models.desc(models.Repo.created))[:10]
    top = models.select(r for r in models.Repo).\
            order_by(models.desc(models.Repo.down_count))[:10]

    error = 'Beta version, only for test for the time now.'
    return flask.render_template('index.html', top_repos=top, new_repos=new, error=error)

@bp.route('/<path:reponame>')
@models.db_session
def repo(reponame):
    repo = models.Repo.get(name=reponame)<commit_msg>add force add button<commit_after># coding: utf-8
import datetime
import time
import json
import flask
import requests
from flask import request, flash, redirect, url_for, render_template

import models

bp = flask.Blueprint('home', __name__)

@bp.route('/ruok', methods=['GET', 'POST'])
def ruok():
    return 'imok'

def cleanname(name):
    for prefix in 'http://', 'https://', '/':
        if name.startswith(prefix):
            name = name[len(prefix):]
    for suffix in '/', '.git':
        if name.endswith(suffix):
            name = name[:-len(suffix)]
    name = name.replace(':', '/')
    return name

def checkrepo(name):
    ''' return desc '''
    payload = {'pkgname': name}
    requests.get('https://gowalker.org/'+name) # call gowalker to load data
    r = requests.get('https://gowalker.org/api/v1/pkginfo', params=payload)
    d = r.json()
    if not d['id']:
        raise Exception('error load package in https://gowalker.org: %s' % r.text)

    if not d['cmd']:
        raise Exception('Repo: [%s] is a go-lib, this platform only support main package' % name)
    return d['synopsis']

@bp.route('/')
@models.db_session
def home():
    address = flask.request.args.get('address')
    if address:
        reponame = cleanname(address)
        if not models.Repo.get(name=reponame):
            try:
                nocheck = 'nocheck-'
                if reponame.startswith(nocheck):
                    reponame = reponame[len(nocheck):]
                    desc = 'unknown desc'
                else:
                    desc = checkrepo(reponame)
            except Exception as e:
                force_add = '''If you confirm this is a go main package. Click <a class="btn btn-warning btn-xs" href="/?address=nocheck-%s">force add</a>''' %(reponame)
                error = str(e) + ' <br>- ' + force_add
                return flask.render_template('index.html', error=flask.Markup(error))
            repo = models.Repo(name=reponame)
            repo.created = datetime.datetime.today()
            repo.description = desc
            repo.author = 'unknown .. unfinished'
            models.commit()

        return flask.redirect('/'+reponame, 302)

    new = models.select(r for r in models.Repo).\
            order_by(models.desc(models.Repo.created))[:10]
    top = models.select(r for r in models.Repo).\
            order_by(models.desc(models.Repo.down_count))[:10]

    error = 'Beta version, only for test for the time now.'
    return flask.render_template('index.html', top_repos=top, new_repos=new, error=error)

@bp.route('/<path:reponame>')
@models.db_session
def repo(reponame):
    repo = models.Repo.get(name=reponame)
{'fraction_non_alphanumeric': 0.14427767354596624, 'fraction_numerical': 0.003377110694183865, 'mean_word_length': 2.484313725490196, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1735581', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1649, 'n_words': 414}