def init_db(): print 'Starting...' with closing(connect_db()) as db: with app.open_resource('schema.sql', mode='r') as f: db.cursor().executescript(f.read()) db.commit() print 'Done.'
def db_insert(dt, interval): db = connect_db() #TODO - check for this filename's existence in DB timestamp = datetime.now().strftime("%Y%m%d%H%M%s") fpath = '%s/%s/%s.avi' % (VIDDIR, interval, dt) fsize = os.stat(fpath).st_size #TODO - prettier tile e.g. March 1, 2014 COLUMNS = "(title, filename, fullpath, interval, datetimestamp, notable, size)" VALUES = "('%s', '%s.avi', '%s', '%s', '%s', 0, '%s')" % \ (dt, dt, fpath, interval, timestamp, fsize) query = "insert into tl_videos %s values %s" % (COLUMNS, VALUES) db.execute(query) db.commit() db.close() # Restart system if video size is below threshold if interval == 'hour' and fsize < 5000000: print "Video size less than 5 MB which likely indicates a problem. Restarting system." email("Timelapse - Restarting Server", "The video " + os.path.basename(fpath) + " was only " + str(fsize) + " bytes. " + \ "This likely indicates a problem with the capture device over the past hour. " + \ "Restarting " + socket.gethostname()) time.sleep(10) envoy.run("sudo reboot")
def update_tweets_db(): login = authorize() settings = {} settings['db'] = secrets.dbase_connection() with closing(connect_db(settings)) as db: handlers_list = pull_handle(db) for handel in handlers_list: fetch_user_statuses(login, handel)
from webapp import connect_db # Crawl through videos and create db references where needed # Run weekly db = connect_db() db.execute("insert into tl_videos (title, filename, fullpath) values ('Day Zero', '20140300', '/path/to/20140300.avi')") db.commit() db.close()