forked from avraampiperidis/imdb_pyscraper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_actor_into_cast.py
More file actions
69 lines (49 loc) · 1.71 KB
/
insert_actor_into_cast.py
File metadata and controls
69 lines (49 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
__author__ = 'abraham'
import MySQLdb
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from utils import *
from db import getCursor
def insert_actor_to_casts(globalmovieid,name,lastname,username):
db = getCursor()
cur = db.cursor()
#check if is in this movie casts
sql = "select personid from Persons where name = %s and lastname = %s "
try:
cur.execute(sql, [name,lastname])
result = cur.fetchall()
for row in result:
personid = row[0]
sql = "select count(1) from Casts where imdbid = %s and personid = %s "
cur.execute(sql, [globalmovieid,personid])
if cur.fetchone()[0]:
print "Actor is in this movie cast"
#done nothing to update
#if its not insert to casts
else:
sql = "insert into Casts(name,lastname,personid,imdbid,moviename) values(%s,%s,%s,%s,%s)"
try:
cur.execute(sql,[name,lastname,personid,globalmovieid,username])
db.commit()
except MySQLdb.Error, e:
db.rollback()
print e
cur.close()
except:
print 'Error...'
db.rollback()
def getPersonsId(name,lastname):
db = getCursor()
cur = db.cursor()
#check if is in this movie casts
sql = "select personid from Persons where name = %s and lastname = %s "
try:
cur.execute(sql,[name,lastname])
result = cur.fetchall()
for row in result:
personid = row[0]
return personid
except MySQLdb.Error, e:
print e