Exemple #1
0
def update_db_if_needed(db, timestamp):
    db.connect()
    res = db.run(
        'raw',
        'SELECT pref_value from `preferences` where pref_key = "force_update"')
    if res[0]['pref_value'] == '1':
        formater = '{:' + (get_db_time_format()) + '}'
        formatted_ts = formater.format(timestamp)
        db.run(
            'raw',
            'update preferences set pref_value = "{0}" where pref_key = "timestamp"'
            .format(formatted_ts))
        db.commit()
    db.disconnect()
Exemple #2
0
def update_db(db, timestamp, local):
    db.connect()
    formater = '{:' + (get_db_time_format()) + '}'
    print(formater)
    formatted_ts = formater.format(timestamp)
    sql = 'REPLACE INTO hashrate (time, local) VALUES("{0}", {1})'.format(
        formatted_ts, local)
    print(sql)
    db.run('raw', sql)
    db.run(
        'raw',
        'update preferences set pref_value = "{0}" where pref_key = "timestamp"'
        .format(formatted_ts))
    db.run(
        'raw',
        'update preferences set pref_value = "0" where pref_key = "force_update"'
    )
    db.commit()
    db.disconnect()
    pass
Exemple #3
0
def get_pools_data():
    timestamp = datetime.datetime.strptime(json.loads(get_timestamp())['result']['timestamp'], defs.get_db_time_format())
    f = open(defs.get_pool_data_file(timestamp), 'r')
    res = get_data_from_file(f)
    f.close()
    return json.dumps({'result': res})