MCPcopy Create free account
hub / github.com/ActiveState/code / write_db

Function write_db

recipes/Python/456361_Paypal_IPN/recipe-456361.py:51–94  ·  view source on GitHub ↗
(f, f1)

Source from the content-addressed store, hash-verified

49
50
51def write_db(f, f1):
52
53 f1.write("... updating database\n")
54
55 try:
56 invoice = f['invoice'].value
57
58 try:
59 street = f['address_street'].value
60 city = f['address_city'].value
61 zipc = f['address_zip'].value
62 country = f["address_country_code"].value
63 firstn = f['first_name'].value
64 lastn = f['last_name'].value
65
66 except KeyError:
67 street = ""
68 city = ""
69 zipc = ""
70 country = ""
71 firstn = ""
72 lastn = ""
73
74 try:
75 #some countries don't have states
76 state = f['address_state'].value
77 except KeyError:
78 state =""
79
80 if f.has_key("custom"):
81 payer_url = f["custom"].value
82
83 query = "INSERT INTO names VALUES ('" + invoice + "', '" + \
84 firstn + "', '" + lastn + "', '" + street + "', '" + city + "', '" + state + "', '" + zipc + "', '" + \
85 country + "', '" + f['payer_email'].value + "', '" + \
86 payer_url + "', '" + f['option_selection1'].value + "', '" + f['option_selection2'].value + "')"
87
88 f1.write(query + "\n")
89 db = MySQLdb.connect(host="localhost", user="username", passwd="passwd",db="db")
90 cursor = db.cursor()
91 cursor.execute (query)
92
93 except:
94 f1.write(''.join(format_exception(*exc_info())))
95
96
97

Callers 1

recipe-456361.pyFile · 0.85

Calls 6

cursorMethod · 0.80
writeMethod · 0.45
has_keyMethod · 0.45
connectMethod · 0.45
executeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected