Guest User

Untitled

a guest
Sep 25th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. def connect(username, created_at, tweet, retweet_count, place , location):
  2. """
  3. connect to MySQL database and insert twitter data
  4. """
  5. try:
  6. con = mysql.connector.connect(host = 'localhost',
  7. database='twitterdb', user='root', password = password, charset = 'utf8')
  8.  
  9.  
  10. if con.is_connected():
  11. """
  12. Insert twitter data
  13. """
  14. cursor = con.cursor()
  15. # twitter, golf
  16. query = "INSERT INTO Golf (username, created_at, tweet, retweet_count,place, location) VALUES (%s, %s, %s, %s, %s, %s)"
  17. cursor.execute(query, (username, created_at, tweet, retweet_count, place, location))
  18. con.commit()
  19.  
  20.  
  21. except Error as e:
  22. print(e)
  23.  
  24. cursor.close()
  25. con.close()
  26.  
  27. return
Add Comment
Please, Sign In to add comment