From cbe691f8c0df72b94476d1c960e42a31f27d0f02 Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Tue, 19 Mar 2013 01:35:52 -0700 Subject: [PATCH] Removed python --- agg.py | 153 --------------------------------------------------------- 1 file changed, 153 deletions(-) delete mode 100755 agg.py diff --git a/agg.py b/agg.py deleted file mode 100755 index 6237d2d..0000000 --- a/agg.py +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/python - -import json, sys, os, time -import subprocess, sqlite3 -import magic - - -colors = {} -colors['yellow'] = '\033[0;33m' -colors['green'] = '\033[0;92m' -colors['purple'] = '\033[0;95m' -colors['red'] = '\033[0;91m' -colors['blue'] = '\033[0;94m' -colors['end'] = '\033[0m' - -video_types = [ 'video/mp4' ] -image_types = [ 'image/jpg' ] - -s3_bucket="s3://agg/" -s3_url="http://agg.s3.amazonaws.com/" - -db = None -_DATABASE_ = 'agg.db' - -def main(): - - # init DB - try: - db = sqlite3.connect(_DATABASE_) - initdb(db); - except sqlite3.Error, e: - print "Error %s:" % e.args[0] - sys.exit(1) - finally: - if db: - db.close() - - # system arguments - if len(sys.argv) < 2: - exit() - if len(sys.argv) == 3: - media_path = sys.argv[2] - media_filename = os.path.split(sys.argv[2])[-1] - action = sys.argv[1] - - if action == "push-data": - # upload database - print green + "Uploading database to s3..." + colors['end'] - cmd = ( "s3cmd put -v --acl-public --guess-mime-type agg.db " + - s3_bucket + _DATABASE_ ) - print cmd - os.system(cmd); - - elif action == "pull-data": - # download database - print colors['green'] + "Downloading database from s3..." + colors['end'] - cmd = "s3cmd get --force " + s3_bucket + _DATABASE_ - print cmd - os.system(cmd); - - elif action == "ul" : - # upload media - - - # determine file type and distinguish if it's an image or a video - mime = magic.from_file(media_path, mime=True) - print colors['yellow'] + "type\t" + colors['end'] + mime - if (mime in video_types): - folder = "v/" - elif (mime in image_types): - folder = "i/" - else: - print colors['red'] + "File is unsupported mime-type" + colors['end'] - - - # check to see if media file already exists - p = subprocess.Popen("s3cmd ls " + s3_bucket + folder + media_filename, - shell=True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) - for line in p.stdout.readlines(): - print line, - print colors['red'] + "File exists." + colors['end'] - exit() - retval = p.wait() - - - # start new entry - new_entry = {} - new_entry['link'] = get_user_input("link ") - new_entry['title'] = get_user_input("title ") - new_entry['desc'] = get_user_input("desc ") - new_entry['name'] = media_filename - new_entry['url'] = s3_url + "v/" + media_filename - new_entry['mime'] = mime - - - print colors['green'] + "Entering data in db" + colors['end'] - try: - db = sqlite3.connect(_DATABASE_) - cur = db.cursor() - cur.execute("INSERT INTO entries VALUES(NULL, DATETIME('NOW'), ?, ?, ?, ?, ?, ?)", ( new_entry['link'], new_entry['title'], new_entry['desc'], new_entry['name'], new_entry['mime'], new_entry['url'])) - db.commit() - data = cur.fetchone() - print data - except sqlite3.Error, e: - print "Error %s:" % e.args[0] - sys.exit(1) - finally: - if db: - db.close() - - print colors['green'] + "Uploading to s3..." + colors['end'] - cmd = "s3cmd put --acl-public --guess-mime-type " + media_path + " " + s3_bucket + folder + media_filename - print cmd - os.system(cmd); - - #print colors['purple'] + json.dumps(new_entry, indent = 2) + colors['end'] - - - # download media via youtube-dl - elif action == "dl": - print "download" - - -def initdb(db): - cur = db.cursor() - cur.execute("CREATE TABLE IF NOT EXISTS entries(" + - "_id integer primary key autoincrement, " + - "created date default CURRENT_DATE, " + - "link TEXT, " + - "title TEXT, " + - "desc TEXT, " + - "name TEXT, " + - "url TEXT, " + - "mime TEXT" + - ")") - - -def sqliteVersion(db): - cur = db.cursor() - cur.execute('SELECT SQLITE_VERSION()') - data = cur.fetchone() - print "SQLite version: %s" % data - - -def get_user_input(question): - while True : - sys.stdout.write(colors['yellow'] + question + "\t" + colors['end']) - choice = raw_input() - return choice - - -if __name__ == "__main__": - main() -- 2.34.1