1
これは私のコードです。私はjsonとtweepyを使用して場所を取得しますか?
place= data['place']['full_name']
#location1= all_data["location"]
cursor.execute(
"INSERT INTO tweeter (time, username, tweet,location) VALUES (%s,%s,%s,%s)",
(time.time(), username, tweet,place))
db.commit()
print((username,tweet))
return True
else:
return True
を場所を取得するには、このステートメントを追加しますが、このdoesnot作業列指数が整数
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
import MySQLdb
import simplejson
from HTMLParser import HTMLParser
db = MySQLdb.connect(
host = 'localhost',
user = 'root',
passwd='',
db='python',
charset='utf8',
use_unicode=True
)
cursor=db.cursor()
ckey = ''
csecret = ''
atoken = ''
asecret = ''
class listener(StreamListener):
def on_data(self, data):
all_data = simplejson.loads(HTMLParser().unescape(data))
#all_data = simplejson.loads(data)
# check to ensure there is text in
# the json data
if 'text' in all_data:
tweet = all_data["text"]
username = all_data["user"]["screen_name"]
でなければなりません:私はこのコードを実行すると、私はエラー 昇給例外 TypeError例外を取得しますこのdef on_status関数は、インターネットからの助けを借りて私に追加されました。
def on_status(self, status):
if status.place:
print 'place:', status.place.full_name
return True
on_event = on_status
def on_error(self, status):
print(status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream (auth ,listener())
twitterStream.filter(track=["Earthquake"],languages = ["en"], stall_warnings = True)
私の問題の解決に手伝ってください。あなたは、MySQLでテーブルを作成する必要があり、その前に
知っていますか? – andersschuller
iは=データ[ "場所"] [ "フルネーム] デフon_status(自己、ステータス)の場所に考える: status.place場合: プリント '場所:'、status.place.full_name リターン真 ON_EVENT = on_status – SmartF