-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCritic.py
More file actions
28 lines (24 loc) · 792 Bytes
/
Critic.py
File metadata and controls
28 lines (24 loc) · 792 Bytes
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
class Critic:
def __init__(self,name,publication, cnx):
values = {}
values['name'] = str(name) #converts from bs navigable string to unicode string
values['publication'] = str(publication)
#add to database
cursor = cnx.cursor()
query = ("select critic_id from critics where name = %s and publication = %s")
inDB = False
self.cid = 0;
cursor.execute(query,(values['name'],values['publication']))
for(critic_id,)in cursor:
inDB = True
self.cid = critic_id
if(not inDB):
#make a new row for this critic
add_critic = ("INSERT INTO critics"
"(name, publication)"
"VALUES (%s, %s)")
critic_data = (values['name'], values['publication'])
cursor.execute(add_critic,critic_data)
self.cid = cursor.lastrowid
cnx.commit()
cursor.close()