python - Inserting tweets into MySQL DB using Tweepy -


i trying use following python code insert parsed out tweets mysql database:

    #-*- coding: utf-8 -*-      __author__ = 'sagars'      import pymysql     import tweepy     import time     import json     tweepy import stream     tweepy import oauthhandler     tweepy.streaming import streamlistener    class listener(streamlistener):   def on_data(self, data):         all_data = json.loads(data)         tweet = all_data["text"]         username = all_data["user"]["screen_name"]          c.execute("insert tweets (tweet_time, username, tweet) values (%s,%s,%s)"                   (time.time(), username, tweet))         print (username, tweet)         return true  def on_error(self, status):     print (status)  auth = oauthhandler(ckey, csecret) auth.set_access_token(atoken, asecret) twitterstream = stream(auth, listener()) twitterstream.filter(track = ["lebron james"]) 

but running following error:

traceback (most recent call last):   file "c:/users/sagars/pycharmprojects/youtube nlp lessons/twitter stream db.py", line 45, in <module>     twitterstream.filter(track = ["lebron james"])   file "c:\python34\lib\site-packages\tweepy\streaming.py", line 428, in filter     self._start(async)   file "c:\python34\lib\site-packages\tweepy\streaming.py", line 346, in _start     self._run()   file "c:\python34\lib\site-packages\tweepy\streaming.py", line 286, in _run     raise exception   file "c:\python34\lib\site-packages\tweepy\streaming.py", line 255, in _run     self._read_loop(resp)   file "c:\python34\lib\site-packages\tweepy\streaming.py", line 309, in _read_loop     self._data(next_status_obj)   file "c:\python34\lib\site-packages\tweepy\streaming.py", line 289, in _data     if self.listener.on_data(data) false:   file "c:/users/sagars/pycharmprojects/youtube nlp lessons/twitter stream db.py", line 35, in on_data     (time.time(), username, tweet)) typeerror: 'str' object not callable 

how can code adjusted avoid error? should tweets parsed out of json object in different way?

you forgot comma before (time.time(), usernam.... etc.

to clarify be

 c.execute("insert tweets (tweet_time,     username, tweet) values (%s,%s,%s)" ,               (time.time(), username, tweet)) 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -