Skip to content

Instantly share code, notes, and snippets.

@DFoly
Created September 25, 2018 16:05
Show Gist options
  • Select an option

  • Save DFoly/f0cb63ad49f02bf625f5699cac39d3c1 to your computer and use it in GitHub Desktop.

Select an option

Save DFoly/f0cb63ad49f02bf625f5699cac39d3c1 to your computer and use it in GitHub Desktop.
connect method
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment