Пример #1
0
import sys
import time
from twython import Twython, TwythonError
from io_helper import twitter_credential_prompt

# Requires Authentication as of Twitter API v1.1
(APP_KEY, APP_SECRET, OAUTH_TOKEN,
 OAUTH_TOKEN_SECRET) = twitter_credential_prompt()
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

# All the available places for trends query
places = twitter.get_available_trends()
country_list = ['India']
places_of_interest = 0
trends_of_ineterest = set([])
places_list = []

for place in places:
    if (place['country'] in country_list):
        print('Name: ', place['name'])
        print('-----------------------')
        places_of_interest += 1
        places_list.append(place)

print('places of interest count - ', len(places_list))

for place in places_list:
    trends_for_place = twitter.get_place_trends(id=place['woeid'])
    print('Got the trends for ', place['name'])
    trends_list = []
    i = 10
Пример #2
0
from twython import TwythonStreamer
from io_helper import twitter_credential_prompt
from io_helper import custom_prompt

class MyStreamer(TwythonStreamer):
    def on_success(self, data):
        if 'text' in data:
            print(data['text'].encode('utf-8'))
        # Want to disconnect after the first result?
        # self.disconnect()

    def on_error(self, status_code, data):
        print(status_code, data)

# Requires Authentication as of Twitter API v1.1
(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) \
			= twitter_credential_prompt()
stream = MyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
track_keyword = custom_prompt('Stream keyword : ')

stream.statuses.filter(track=track_keyword)
# stream.user()
# Read the authenticated users home timeline
# (what they see on Twitter) in real-time
# stream.site(follow='twitter')