Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql.cursors
- # connect to the database and return list of tokens
- def get_tweets():
- try:
- connection = pymysql.connect(host='localhost',
- user='xxx',
- password='xxx',
- db='xxx',
- charset='utf8',
- use_unicode=True,
- cursorclass=pymysql.cursors.DictCursor)
- except pymysql.err.OperationalError as err:
- print("Operational Error: {0}".format(err))
- try:
- with connection.cursor() as cursor:
- # read all the tokens
- sql = 'SELECT `text` FROM `tweets`'
- cursor.execute(sql)
- result = cursor.fetchall()
- for i in result:
- print(i['text'])
- finally:
- connection.close()
- get_tweets()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement