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()
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)
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)
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()})
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
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
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
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()
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)
#!/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))
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)
def main(): html = get_html( "http://books.toscrape.com/") res = select(html) store(res) print("Done")
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)
def storeFn(cmd): if len(cmd) != 2: print('store command needs: file name') return db.store(cmd[1])