Ejemplo n.º 1
0
def edit_description(name):
    if 'days' not in request.form:
        return render_template('error.html',
                               error='No "days" in POST params',
                               code='NONE',
                               backlink='/my/edit/' + name)
    if 'url' not in request.form:
        return render_template('error.html',
                               error='No "url" in POST params',
                               code='NONE',
                               backlink='/my/edit/' + name)
    if 'description' not in request.form:
        return render_template('error.html',
                               error='No "description" in POST params',
                               code='NONE',
                               backlink='/my/edit/' + name)

    resource = {
        'url': request.form['url'],
        'description': request.form['description']
    }

    blk = DI.get_blockchain()
    data = blk.edit_resource(name, resource, int(request.form['days']))

    if data['error'] and data['error']['code'] < 0:
        return render_template('error.html',
                               error=data['error']['message'],
                               code=data['error']['code'],
                               backlink='/my_descriptions')
    else:
        return render_template('ok.html',
                               nav='my',
                               message='Resource "' + name + '" edited OK',
                               backlink='/my_descriptions')
Ejemplo n.º 2
0
def hello_world():
    blk = DI.get_blockchain()
    try:
        data = blk.get_info()
        return render_template('main.html', data=data['result'])
    except Exception:
        return redirect('/config')
Ejemplo n.º 3
0
def show_edit(resource):
    blk = DI.get_blockchain()
    data = blk.show_resource(resource)
    resourse = data['result']
    decoded = json.loads(resourse['value'])
    resourse.update(decoded)
    return render_template('edit.html', nav='my', resourse=resourse)
Ejemplo n.º 4
0
def add(resource_id):
    if 'days' not in request.form:
        return render_template('error.html',
                               error='No "days" in POST params',
                               code='NONE',
                               backlink='/add/' + resource_id)
    if 'url' not in request.form:
        return render_template('error.html',
                               error='No "url" in POST params',
                               code='NONE',
                               backlink='/add/' + resource_id)
    if 'description' not in request.form:
        return render_template('error.html',
                               error='No "description" in POST params',
                               code='NONE',
                               backlink='/add/' + resource_id)

    resource = {
        'url': request.form['url'],
        'description': request.form['description']
    }
    blk = DI.get_blockchain()
    data = blk.post_resource(resource, int(request.form['days']))

    if data['error'] and data['error']['code'] < 0:
        return render_template('error.html',
                               error=data['error']['message'],
                               code=data['error']['code'],
                               backlink='/my')
    else:
        return render_template('ok.html',
                               message='Resource submitted OK',
                               backlink='/my')
Ejemplo n.º 5
0
def show_networks():
    rep = DI.get_repository()
    blk = DI.get_blockchain()
    upd = Updater(rep, blk)
    upd.check()

    networks = rep.read_networks()
    return render_template('list/networks.html',
                           title='Main',
                           nav='tags',
                           networks=networks)
Ejemplo n.º 6
0
def delete(resource):
    blk = DI.get_blockchain()
    data = blk.delete_resource(resource)

    if data['error'] and data['error']['code'] < 0:
        return render_template('error.html',
                               error=data['error']['message'],
                               code=data['error']['code'],
                               backlink='/my')
    else:
        return render_template('ok.html', message='DELETED OK', backlink='/my')
Ejemplo n.º 7
0
def submit():
    if 'days' not in request.form:
        return render_template('error.html',
                               error='No "days" in POST params',
                               code='NONE',
                               backlink='/submit')
    if 'url' not in request.form:
        return render_template('error.html',
                               error='No "url" in POST params',
                               code='NONE',
                               backlink='/submit')
    if 'network' not in request.form:
        return render_template('error.html',
                               error='No "network" in POST params',
                               code='NONE',
                               backlink='/submit')
    if 'type' not in request.form:
        return render_template('error.html',
                               error='No "type" in POST params',
                               code='NONE',
                               backlink='/submit')
    if 'tags' not in request.form:
        return render_template('error.html',
                               error='No "tags" in POST params',
                               code='NONE',
                               backlink='/submit')
    if 'description' not in request.form:
        return render_template('error.html',
                               error='No "description" in POST params',
                               code='NONE',
                               backlink='/submit')

    resource = {
        'url': request.form['url'],
        'network': request.form['network'],
        'type': request.form['type'],
        'lang': request.form['lang'],
        'tags': request.form['tags'],
        'description': request.form['description']
    }
    blk = DI.get_blockchain()
    data = blk.post_resource(resource, int(request.form['days']))

    if data['error'] and data['error']['code'] < 0:
        return render_template('error.html',
                               error=data['error']['message'],
                               code=data['error']['code'],
                               backlink='/my')
    else:
        return render_template('ok.html',
                               message='Resource submitted OK',
                               backlink='/my')
Ejemplo n.º 8
0
def test():
    # rep = DI.get_repository()
    # res = rep.search_resources_by_url('youtube')
    # print(res)
    # res = rep.search_resources_by_description('Биткоин')
    # print(res)
    # rep = DI.get_repository()
    # blk = DI.get_blockchain()
    # upd = Updater(rep, blk)
    # print(upd.check())

    blk = DI.get_blockchain()
    print(blk.check())
    return 'OK'


# app.run()
Ejemplo n.º 9
0
def search():
    rep = DI.get_repository()
    blk = DI.get_blockchain()
    upd = Updater(rep, blk)
    upd.check()

    resources = []
    if request.form['type'] == 'url':
        resources = rep.search_resources_by_url(request.form['search'])
    elif request.form['type'] == 'description':
        resources = rep.search_resources_by_description(request.form['search'])
    # print(resources)
    return render_template('list/search.html',
                           nav='search',
                           title='Search',
                           search=request.form['search'],
                           type=request.form['type'],
                           resources=resources)
Ejemplo n.º 10
0
def post_config():
    Config.save_config({
        'host': request.form['host'],
        'port': int(request.form['port']),
        'user': request.form['user'],
        'password': request.form['password']
    })

    blk = DI.get_blockchain()
    if blk.check():
        result = 'Connection OK =)'
    else:
        result = 'FAILED'

    return render_template('config.html',
                           nav='config',
                           title='Config',
                           result=result,
                           data=request.form)
Ejemplo n.º 11
0
def show_my():
    blk = DI.get_blockchain()
    if not blk.check():
        return render_template('error_rpc.html', nav='my')

    records = blk.get_my()
    my_records = []

    for record in records:
        record['decoded'] = json.loads(record['value'])
        record['expires_in'] = round(record['expires_in'] / 175)

    for record in records:
        if 'network' in record['decoded'] and 'type' in record[
                'decoded'] and 'lang' in record[
                    'decoded'] and 'tags' in record['decoded']:
            my_records.append(record)

    return render_template('my.html', records=my_records, nav='my')
Ejemplo n.º 12
0
def sync():
    rep = DI.get_repository()
    blk = DI.get_blockchain()
    upd = Updater(rep, blk)
    upd.sync()
    return 'ok'