Last active
August 29, 2015 14:22
-
-
Save eduardosan/84e9cc86221c05d265d1 to your computer and use it in GitHub Desktop.
Extrai dados do Twitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env python | |
# -*- coding: utf-8 -*- | |
import twitter | |
import pprint | |
api = twitter.Api(consumer_key='consumer_key', | |
consumer_secret='consumer_secret', | |
access_token_key='access_token', | |
access_token_secret='access_token_secret') | |
api.VerifyCredentials() | |
# <twitter.user.User object at 0x02EE5EF0> | |
status_list = api.GetSearch( | |
geocode=None, term=u”ladrão”, since_id=None, | |
lang=’pt’, count=10, result_type=’recent’ | |
) | |
print(status_list) | |
# [<twitter.status.Status object at 0x03078AF0>, <twitter.status.Status object at 0x03078B90>, <twitter.status.Status object at 0x03078C50>, <twitter.status.Status object at 0x03078D30>, <twitter.status.Status object at 0x03078D90>, <twitter.status.Status object at 0x03078DF0>, <twitter.status.Status object at 0x03078E50>, <twitter.status.Status object at 0x03078F10>, <twitter.status.Status object at 0x03078F70>, <twitter.status.Status object at 0x03088030>] | |
help(twitter.Status) | |
status_list[0].GetText() | |
# u’RT @PandaRcds: @edmilsonpapo10 @OThereza MAIS UMA DAS MENTIRAS DO LULA LADR\xc3O DO BRASIL!’ | |
hashtags = dict() | |
for status in status_list: | |
status_hashtags = status.hashtags | |
for hash in status_hashtags: | |
if hashtags.get(hash.text) is None: | |
hashtags[hash] = 1 | |
else: | |
hashtags[hash] += 1 | |
pp = pprint.PrettyPrinter(indent=4) | |
pp.pprint(hashtags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment