Created
September 25, 2018 16:05
-
-
Save DFoly/f0cb63ad49f02bf625f5699cac39d3c1 to your computer and use it in GitHub Desktop.
connect method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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