Created
February 14, 2013 00:10
-
-
Save anonymous/4949607 to your computer and use it in GitHub Desktop.
Pasted from IPython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db.OnAirInfo.aggregate() | |
| con = MySQLdb.connect('localhost', 'testuser', 'cbslocal', 'stations') | |
| import MySQLdb | |
| con = MySQLdb.connect('localhost', 'testuser', 'cbslocal', 'stations') | |
| from pymongo import MongoClient | |
| connection = MongoClient() | |
| db = connection.avalon | |
| for a in db.OnAirInfo.find({"playtime": {"$gt": startr, "$lt": endr}}): | |
| print a | |
| from datetime import datetime | |
| startr = datetime(2013,1,19, 14,44) | |
| endr = datetime(2013,1,19, 14,54) | |
| for a in db.OnAirInfo.find({"playtime": {"$gt": startr, "$lt": endr}}): | |
| print a | |
| items = db.OnAirInfo.find({"playtime": {"$gt": startr, "$lt": endr}}) | |
| list(items) | |
| len(items) | |
| items = len(items) | |
| items = db.OnAirInfo.find({"playtime": {"$gt": startr, "$lt": endr}}) | |
| items = list(db.OnAirInfo.find({"playtime": {"$gt": startr, "$lt": endr}}) | |
| ) | |
| items = list(db.OnAirInfo.find({"playtime": {"$gt": startr, "$lt": endr}})) | |
| len(items) | |
| items | |
| [ v['abum'] for k, v in x.iteritems() for x in items] | |
| [ v['abum'] for k, v in x.iteritems() for x in items] | |
| [x for x in items] | |
| [x.keys() for x in items] | |
| [x.iteritems() for x in items] | |
| [for k,v in x.iteritems() for x in items] | |
| [k for k,v in x.iteritems() for x in items] | |
| [v['album'] for k,v in x.iteritems() for x in items] | |
| [v for k, v in x.iteritems() for x in items] | |
| [k for k, v in x.iteritems() for x in items] | |
| [v['title'] for k, v in x.iteritems() for x in items] | |
| [v.get('title') for k, v in x.iteritems() for x in items] | |
| [type(v) for k, v in x.iteritems() for x in items] | |
| [type(v) for k, v in x.iteritems() for x in items] | |
| {k,v for k, v in items[0]} | |
| {k,v for k, v in items[0].iteritems()} | |
| {k:v for k, v in items[0].iteritems()} | |
| {k:v for k, v in items[0].iteritems() if k in ('album')} | |
| {k:v for k, v in items[0].iteritems() if k in ['albums']} | |
| {k:v for k, v in items[0].iteritems() if k in ['album']} | |
| {k:v for k, v in items[0].iteritems() if k in ['album', 'artist']} | |
| [ {k:v for k, v in x.iteritems() if k in ['album', 'artist']} for x in items]} | |
| [ {k:v for k, v in x.iteritems() if k in ['album', 'artist']} for x in items] | |
| items | |
| [ {k:v for k, v in x.iteritems() if k in ['album', 'artist', 'id']} for x in items] | |
| import MySQLdb | |
| con = MySQLdb.connect('localhost', 'testuser', 'cbslocal', 'stations') | |
| cur = con.cursor() | |
| req_out = [ {k:v for k, v in x.iteritems() if k in ['album', 'artist', 'id', 'RoviID', 'duration', 'title', 'playtime']} for x in items] | |
| req_out | |
| req_out | |
| sql='''\ | |
| INSERT INTO OnAirHistory(id, idRovi, TimePlayed, SongTitle, AlbumTitle, ArtistName, Duration, idStation) | |
| VALUES (%s, %s, %s, %s, %s, %s, %s) | |
| ''' | |
| for a in req_out: | |
| cursor.executemany(sql, a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id')) | |
| for a in req_out: | |
| cur.executemany(sql, a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id')) | |
| for a in req_out: | |
| cur.executemany(sql, (a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id'))) | |
| req_out | |
| sql | |
| for a in req_out: | |
| cur.executemany(sql, (a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id'),)) | |
| a | |
| for a in req_out: | |
| cur.executemany(sql, [a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id')]) | |
| for a in req_out: | |
| cur.executemany(sql, (a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id'),)) | |
| sql % (a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id')) | |
| for a in req_out: | |
| cur.executemany(sql, ((a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id')),)) | |
| for a in req_out: | |
| cur.executemany(sql, [(a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id'))]) | |
| sql | |
| for a in req_out: | |
| cur.executemany(sql, [(a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id'))]) | |
| sql | |
| sql = INSERT INTO OnAirHistory(id, idRovi, TimePlayed, SongTitle, AlbumTitle, ArtistName, Duration, idStation)\nVALUES (NULL, %s, %s, %s, %s, %s, %s, %s)\n' | |
| sql = 'INSERT INTO OnAirHistory(id, idRovi, TimePlayed, SongTitle, AlbumTitle, ArtistName, Duration, idStation)\nVALUES (NULL, %s, %s, %s, %s, %s, %s, %s)\n' | |
| for a in req_out: | |
| cur.executemany(sql, [(a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id'))]) | |
| sqld = 'drop table OnAirHistory' | |
| cur.execute(sqld) | |
| sqlc = """\ | |
| CREATE TABLE IF NOT EXISTS OnAirHistory (id int auto_increment primary key, | |
| idRovi int, | |
| TimePlayed datetime, | |
| SongTitle Varchar(30), | |
| AlbumTitle Varchar(30), | |
| ArtistName varchar(30), | |
| Duration int, | |
| idStation int)""" | |
| cur.execute(sqlc) | |
| cur.execute(sqld) | |
| sqlc = """\ | |
| CREATE TABLE IF NOT EXISTS OnAirHistory (id int auto_increment primary key, | |
| idRovi varchar(30), | |
| TimePlayed datetime, | |
| SongTitle Varchar(30), | |
| AlbumTitle Varchar(30), | |
| ArtistName varchar(30), | |
| Duration int, | |
| idStation int)""" | |
| cur.execute(sqlc) | |
| sql | |
| for a in req_out: | |
| cur.executemany(sql, [(a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id'))]) | |
| req_out | |
| for a in req_out: | |
| cur.executemany(sql, [(a.get('RoviID'), a.get('playtime'), a.get('title'), a.get('album'), a.get('artist'), a.get('duration'), a.get('id'))]) | |
| connection = MongoClient() | |
| connection | |
| DBNAME = avalon | |
| DBNAME = 'avalon' | |
| db = connection.DBNAME | |
| db | |
| db = connection[DBNAME] | |
| db | |
| db.collection_names | |
| print db.collection_names | |
| collect = db.collection_names | |
| collect | |
| collect == "avalon" | |
| collect.im_func | |
| collect.im_self | |
| db = connection[DBNAME] | |
| db | |
| db.collection_names | |
| for a in db.collection_names: | |
| print a | |
| db.collection_names() | |
| MONGO_COLLECTION_NAME = 'OnAirInfo' | |
| if MONGO_COLLECTION_NAME in db.collection_name(): | |
| print "yay" | |
| else: | |
| print "nah" | |
| for a in db.collection_names(): | |
| print a | |
| MONGO_COLLECTION_NAME | |
| if MONGO_COLLECTION_NAME in list(db.collection_name()): | |
| print "yay" | |
| else: | |
| print "nah" | |
| names_c = db.collection_names() | |
| names_c | |
| if MONGO_COLLECTION_NAME in names_c: | |
| print "yay" | |
| items_t = list(db.MONGO_COLLECTION_NAME.find({"playtime": {"$gt": startr, "$lt": endr}}) | |
| ) | |
| items_t | |
| db.MONGO_COLLECTION_NAME | |
| db['MONGO_COLLECTION_NAME'] | |
| MONGO_COLLECTION_NAME | |
| if 'OnAirInfo' in names_c: | |
| print "yay" | |
| hist | |
| %pastebin 1-1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment