imdb cara list to films table


import MySQLdb
import sys
try:
conn = MySQLdb.connect (host = "SQL09.FREEMYSQL.NET",
user = "utsavsabharwal",
passwd = "primanuts",
db = "moviebook")
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)
cursor = conn.cursor ()
uid=0


f = open("/home/tes/workspace/tests/src/mpaa-ratings-reasons.list", "r")
c=f.readlines()

year=""
nameoffilm=""
for x in range(0, len(c)-1):
if(c[x][0]=='M' and c[x][1]=='V'):
for y in range(0, len(c[x])-1):
if(c[x][y]=='('):
for z in range(y+1,y+5):
year+=c[x][z]
for z in range(3,y):
nameoffilm+=c[x][z]
print uid
print year
print nameoffilm
uid=uid+1
year=""
nameoffilm=""
okies={'uid':'uid','name':'name','year':'year'}
cursor.execute(u'''insert into films (uid, name, year) values(%(uid)s, %(name)s, %(year)s)''', okies)
break

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: