-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProducts.py
More file actions
36 lines (31 loc) · 1.17 KB
/
Products.py
File metadata and controls
36 lines (31 loc) · 1.17 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
from connection import *
class Products:
def __init__(self, name, amazon_url, ebay_url, amazon_price, ebay_price):
self.name = name
self.amazon_url = amazon_url
self.ebay_url = ebay_url
self.amazon_price = amazon_price
self.ebay_price = ebay_price
def save_products(self):
try:
conn = connect()
cursor = conn.cursor()
sql = 'insert into products (name, amazon_url, ebay_url, amazon_price, ebay_price) values (%s, %s, %s, %s, %s)'
datos = (self.name, self.amazon_url, self.ebay_url, self.amazon_price, self.ebay_price)
cursor.execute(sql, datos)
conn.commit()
conn.close()
return "Productos guardados"
except mysql.Error as err:
return "Ha ocurrido un error"
def get_products(self):
try:
conn = connect()
cursor = conn.cursor()
sql = 'select * from products'
cursor.execute(sql)
products = cursor.fetchall()
conn.close()
return products
except mysql.Error as err:
return "Ha ocurrido un error"