-
Notifications
You must be signed in to change notification settings - Fork 0
/
mySQL_ProductLinks.py
52 lines (36 loc) · 1.85 KB
/
mySQL_ProductLinks.py
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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from msedge.selenium_tools import Edge, EdgeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
import time
from selenium.common.exceptions import NoSuchElementException
import mysql.connector
# Checks the SQL database to see if the product already exists
def Check_If_Exist(mycursor, full_product_name):
mycursor.execute("SELECT * FROM ProductLinks WHERE full_product_name = %s GROUP BY full_product_name", (full_product_name,))
results = mycursor.fetchall()
rowcount = mycursor.rowcount
if rowcount:
return True
else:
return False
# Fetches the links of the relevant product when it exists in the SQL database
def SQL_Get_Links(mycursor, full_product_name):
mycursor.execute("SELECT software_link, specifications_link, maintenance_link From ProductLinks WHERE full_product_name = %s", (full_product_name,))
result = (mycursor.fetchall()[0])
return result[0], result[1], result[2]
# Stores the product's links into the SQL database
def SQL_Store_Links(mycursor, db, full_product_name, software_link, specifications_link, maintenance_link):
'''
mycursor.execute("CREATE DATABASE HP")
mycursor.execute("CREATE TABLE ProductLinks (full_product_name VARCHAR(100) PRIMARY KEY, software_link VARCHAR(255), specifications_link VARCHAR(255), maintenance_link VARCHAR(255))")
mycursor.execute("DESCRIBE ProductLinks")
mycursor.execute("SELECT * FROM ProductLinks")
for x in mycursor:
print(x)
'''
sql = "INSERT INTO ProductLinks (full_product_name, software_link, specifications_link, maintenance_link) VALUES (%s, %s, %s, %s)"
val = (full_product_name, software_link, specifications_link, maintenance_link)
mycursor.execute(sql, val)
db.commit()