Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def connect(username, created_at, tweet, retweet_count, place , location):
- """
- connect to MySQL database and insert twitter data
- """
- try:
- con = mysql.connector.connect(host = 'localhost',
- database='twitterdb', user='root', password = password, charset = 'utf8')
- if con.is_connected():
- """
- Insert twitter data
- """
- cursor = con.cursor()
- # twitter, golf
- query = "INSERT INTO Golf (username, created_at, tweet, retweet_count,place, location) VALUES (%s, %s, %s, %s, %s, %s)"
- cursor.execute(query, (username, created_at, tweet, retweet_count, place, location))
- con.commit()
- except Error as e:
- print(e)
- cursor.close()
- con.close()
- return
Add Comment
Please, Sign In to add comment