· 4 years ago · Dec 14, 2020, 09:36 AM
1import mysql.connector
2import re
3
4def pageName(link):
5 match = re.search(r'.*\/(.*)\?', link)
6 tableName = match[1]
7 tableName = tableName.replace('-',"_")
8 return tableName
9
10def tableCreation(name, cursor):
11 tableQuery = "CREATE TABLE IF NOT EXISTS " + name + "(ID INT AUTO_INCREMENT PRIMARY KEY ," \
12 "Title TEXT CHARACTER SET utf8," \
13 "Price FLOAT(10,2)," \
14 "ImageLink TEXT);"
15 cursor.execute(tableQuery)
16
17
18
19def importingData(tableName, title, price, imageLink, cursor):
20 insertQuery = "INSERT INTO " + tableName + " (Title, Price, ImageLink) VALUES (%s, %s, %s)"
21 values = (title, price, imageLink)
22 cursor.execute(insertQuery, values)
23 cursor.execute(insertQuery, values)
24
25