Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector
- '''
- mysqlclient
- ***Not compatible with Python 3.5***
- Must use Python 3.4
- https://mysqlclient.readthedocs.io/en/latest/
- https://github.com/PyMySQL/mysqlclient-python
- sudo apt-get install python-dev libmysqlclient-dev
- sudo apt-get install python3-dev
- sudo pip3 install mysqlclient
- '''
- '''
- MySQL Connector
- Compatible with Python 3.5
- '''
- conn = mysql.connector.connect(user='root', password='password',database='test3db')
- c = conn.cursor()
- value = 1
- insert = "INSERT INTO Table (Column, Column, Column, Column) VALUES (%s, %s, %s, %s)"
- c.execute(insert, (value, value, value, value))
- conn.commit()
- domain = 'example'
- model = 1
- price = 2
- url = 'www.example.com'
- # "UPDATE Prices SET bestbuy=%s, bestbuy_link = %s WHERE ModelNumber = %s"
- update_prices = ("UPDATE Prices SET " + domain + " = %s, " + domain + "_link = %s WHERE ModelNumber = %s")
- c.execute(update_prices, (price, url, model))
- conn.commit()
- def data_entry(domain, model, price, url):
- update_prices = ("UPDATE Prices SET "
- + domain + " = %s, "
- + domain + "_link = %s WHERE ModelNumber = %s")
- c.execute(update_prices, (price, url, model))
- conn.commit()
- def data_entry2(self, model, price, url):
- # "INSERT INTO Prices (ModelNumber, bestbuy, bestbuy_link, bestbuy_time VALUES (%s, %s, %s, %s)"
- insert = "INSERT INTO Prices (ModelNumber, bestbuy, bestbuy_link, bestbuy_time) VALUES (%s, %s, %s, %s)"
- insert_variable_domain = "INSERT INTO Prices (ModelNumber, " + domain + ", " + domain + "_link, " + domain + "_time) VALUES (%s, %s, %s, %s)"
- c.execute(insert, (model, price, url, date_time))
- conn.commit()
Add Comment
Please, Sign In to add comment