Exemplo n.º 1
0
def main():
    logger = logging.getLogger('poke-receiver')
    logger.addHandler(logging.FileHandler(settings.LOGFILE_RECEIVER))
    logger.setLevel(logging.INFO)
    logger.info("receiver.py started")
    conn = db.connect(settings.DATABASE)
    run = True
    i = timestamp()
    while run:
        i += 1
        try:
            data = pickle.load(sys.stdin)
        except EOFError:
            run = False
        except pickle.UnpicklingError:
            logger.error("couldn't unpickle sys.stdin, ignoring...")
        else:
            db.store(conn, data, i)
            logger.info("data stored: %s %s" % (i, data))
        if i % settings.DB_COMPRESSION_INTERVAL == 0:
            db.compress(conn, i)
            conn.close()
            try:
                time.sleep(settings.DB_COMPRESSION_SLEEP)
            except KeyboardInterrupt:
                run = False
            else:
                conn = db.connect(settings.DATABASE)
                logger.info("db compressed, reconnected")
    conn.close()
Exemplo n.º 2
0
def learn_song(filename):
    song_name, tags, sig = read_audiofile(filename)
    addresses, times = fp.get_addresses(fp.get_filtered_spectrogram(sig))

    basename = os.path.basename(filename)
    name, ext = os.path.splitext(basename)
    db.store(addresses, times, hash_metadata(filename, tags), name)
Exemplo n.º 3
0
def main():
    logger = logging.getLogger('poke-receiver')
    logger.addHandler(logging.FileHandler(settings.LOGFILE_RECEIVER)) 
    logger.setLevel(logging.INFO)    
    logger.info("receiver.py started")
    conn = db.connect(settings.DATABASE)
    run = True
    i = timestamp()
    while run:
        i += 1
        try:
            data = pickle.load(sys.stdin)
        except EOFError:
            run = False
        except pickle.UnpicklingError:
            logger.error("couldn't unpickle sys.stdin, ignoring...")
        else:            
            db.store(conn, data, i)
            logger.info("data stored: %s %s" % (i, data))
        if i % settings.DB_COMPRESSION_INTERVAL == 0:
            db.compress(conn, i)
            conn.close()
            try:
                time.sleep(settings.DB_COMPRESSION_SLEEP)
            except KeyboardInterrupt:
                run = False
            else:
                conn = db.connect(settings.DATABASE)
                logger.info("db compressed, reconnected")
    conn.close()
Exemplo n.º 4
0
def reg_ajax():
    url = request.form['urly']
    tag = tag_for(url)
    log.info('register %s %r', tag, url)
    try:
        store(tag, url)
    except:
        log.exception('register to db')
    return jsonify(tag=tag)
Exemplo n.º 5
0
def add_node(request):

    nodes = retrieve('nodes') or []
    body = json.loads(request.body)

    val = body['val']
    node = Node(val)
    nodes += [node.as_dict()]

    store('nodes', nodes)

    return JsonResponse({'data': node.as_dict()})
Exemplo n.º 6
0
def toggleDifficulty(num):
	assert type(num) is int
	
	global SETTINGS_DIFFICULTY
	
	# Change setting
	SETTINGS_DIFFICULTY = num
	
	# Store setting
	db.store('setting', 'difficulty', SETTINGS_DIFFICULTY)
	
	return SETTINGS_DIFFICULTY
Exemplo n.º 7
0
def toggleSound():
	global SETTINGS_SOUND
	
	# Change setting
	if SETTINGS_SOUND == True:
		SETTINGS_SOUND = False
	else:
		SETTINGS_SOUND = True
	
	# Store setting
	db.store('setting', 'sound', SETTINGS_SOUND)
	
	return SETTINGS_SOUND
Exemplo n.º 8
0
def toggleMusic():
	global SETTINGS_MUSIC
	
	# Change setting
	if SETTINGS_MUSIC == True:
		SETTINGS_MUSIC = False
		music.stop()
	else:
		SETTINGS_MUSIC = True
		music.play('01')
	
	# Store setting
	db.store('setting', 'music', SETTINGS_MUSIC)
	
	return SETTINGS_MUSIC
Exemplo n.º 9
0
def fix(track, callback):
    """Looks up the track and fixes it if possible, calling the callback with status updates"""
    callback("Fixing %(artist)s - $(name)s (%(duration)d):" % track)
    candidates = TrackTrie()
    for permutation in _PermutationGenerator(track.lookupInfo):
        for candidate in itms.search(permutation):
            if abs(candidate["duration"] - track["duration"]) <= db.config('max_song_delta'):
                callback("found candidate: %(artist)s - $(name)s (%(duration)d)" % track)
                candidates.add(candidate)
            else:
                callback("found candidate: %(artist)s - $(name)s (%(duration)d), rejected due to time mismatch" % track)
                pass
        if len(candidates) != 0: break
    if len(candidates) == 0: 
        callback("No suitable candidates found")
        return
    best = candidates.pick(track)
    callback("Picked best: %(artist)s - $(name)s (%(duration)d)" % best)
    db.store(track)
    track.replace(best)
    track.save()
Exemplo n.º 10
0
def scan():
    s = save_finger.write()
    s1 = s[0]
    id = request.form['id']
    acc = request.form['acc']
    vill = request.form['vill']
    name = request.form['name']
    age = request.form['age']
    gender = request.form['gender']
    data = {
        'scan': s[1],
        'id': id,
        'acc': acc,
        'vill': vill,
        'name': name,
        'age': age,
        'gender': gender
    }
    data1 = {0: id, 1: acc, 2: vill, 3: name, 4: age, 5: gender, 6: s1}
    db.store(data1)
    return render_template('regi.html', **data)
Exemplo n.º 11
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import time
from time import strftime
import cgitb,cgi
import db
import json
import twitter,watson
cgitb.enable()

print("Content-Type: application/json;charset=utf-8")
print()

query_string = cgi.FieldStorage().getvalue('q').upper()
#case insensitive
if query_string is None:
	print("{'error':'Empty query'}")
else:
	tweets=twitter.search(query_string)
	db.store(query_string,time.time(),tweets,watson.analyze(tweets))
	ret=db.search(query_string)
	result=[]
	for doc in ret:
		result.append({"id":doc["_id"], "time":doc["time"]})
	print(json.dumps(result))
Exemplo n.º 12
0
        logger.warn('Could not locate survey %s' % surname, e)

    logger.info('Pulling %i entries for %s' % (len(walk(cd).next()[1]), surname))
    cont = []
    rel = []

    #go through all the entries for a given survey
    for sl in walk(cd).next()[1]:
        ent = _get_an_entry(join(cd, sl) + '/', surname)
        cont += [ent['content']]

    cont, rel = _break_up(cont)

    #store main entries
    logger.info('***Storing main table entries***')
    db.store(cont, ent['id'])

    logger.info('***Storing relational info***')
    #store relational entries'
    db.relational_ents(schema, surname, rel)

    #get and store OSM data
    osm.store_an_osm(cont, ent['id'])


def get_all_surveys(schema):
    """ iterate through all surveys"""
    base = DEST_LOC + DV
    surveys = [f for f in listdir(base) if not isfile(join(base, f))]
    logger.info('****Extracting the following surveys...****')
    logger.info(surveys)
Exemplo n.º 13
0
def main():
    html = get_html(
        "http://books.toscrape.com/")
    res = select(html)
    store(res)
    print("Done")
Exemplo n.º 14
0
    logger.info('Pulling %i entries for %s' %
                (len(walk(cd).next()[1]), surname))
    cont = []
    rel = []

    # go through all the entries for a given survey
    for sl in walk(cd).next()[1]:
        ent = _get_an_entry(join(cd, sl) + '/', surname)
        cont += [ent['content']]

    cont, rel = _break_up(cont)

    # store main entries
    logger.info('***Storing main table entries***')
    db.store(cont, ent['id'])

    logger.info('***Storing relational info***')
    # store relational entries'
    db.relational_ents(schema, surname, rel)

    # get and store OSM data
    osm.store_an_osm(cont, ent['id'])


def get_all_surveys(schema):
    """ iterate through all surveys"""
    base = DEST_LOC + DV
    surveys = [f for f in listdir(base) if not isfile(join(base, f))]
    logger.info('****Extracting the following surveys...****')
    logger.info(surveys)
Exemplo n.º 15
0
def storeFn(cmd):
    if len(cmd) != 2:
        print('store command needs: file name')
        return
    db.store(cmd[1])