मैं ट्वीट स्थान का उपयोग कर ट्वीट डाउनलोड करने के लिए tweepy का उपयोग करने की कोशिश कर रहा हूं, न कि उपयोगकर्ता के स्थान से। वर्तमान में, मैं उपयोगकर्ता स्थान के साथ ट्वीट्स डाउनलोड कर सकता हूं लेकिन ट्वीट्स स्थान प्राप्त करने में सक्षम नहीं हूं, भले ही geo_enabled
सही हो।ट्वीट स्थान और उपयोगकर्ता स्थान द्वारा स्क्रैप ट्वीट
उदाहरण के लिए, मान लीजिए user_a
न्यूयॉर्क से है लेकिन वह कैलिफ़ोर्निया से ट्वीट करता है। मैं उपयोगकर्ता उपयोगकर्ता, न्यूयॉर्क, और ट्वीट स्थान, कैलिफ़ोर्निया दोनों चाहता हूं।
कोड:
import tweepy
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import pandas as pd
import json
import csv
import sys
reload(sys)
sys.setdefaultencoding('utf8')
ckey = 'key'
csecret = 'secret'
atoken = 'token'
asecret = 'secret'
#csvfile = open('StreamSearch.csv','a')
#csvwriter = csv.writer(csvfile, delimiter = ',')
class StdOutListener(StreamListener):
def __init__(self, api=None):
super(StdOutListener, self).__init__()
self.num_tweets = 0
def on_data(self, data):
self.num_tweets += 1
if self.num_tweets < 5: #Remove the limit of no. of tweets to 5
print data
return True
else:
return False
def on_error(self, status):
print status
l = StdOutListener()
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
stream = Stream(auth, l)
stream.filter(locations = [80.10,12.90,80.33,13.24]) #user location
आउटपुट
userLocation, userTimezone, Coordinates,GeoEnabled, Language, TweetPlace
London,UK Amsterdam FALSE en null
Aachen,Germany Berlin TRUE de null
Kewaunee Wi TRUE en null
Connecticut, Eastern Time (US & Canada) TRUE en null
TRUE en null
Lahore, City of Gardens London TRUE en null
NAU class of 2018. Arizona FALSE en null
FALSE en null
Pacific Time (US & Canada) FALSE en null
ऊपर दिए गए उत्पादन बड़े पैमाने पर डेटा का संस्करण साफ किया जाता है। भले ही Geolocation
सक्षम है, मैं ट्वीट स्थान प्राप्त नहीं कर पा रहा हूं और न ही co-ordinates
।
यह बहुत व्यापक प्रश्न है, हमें बताएं कि आपने क्या प्रयास किया है। – SIslam
@SIslam कोड और आउटपुट –
शामिल हो सकता है- http://stackoverflow.com/a/16892093/4065350 –