In [1]:
import tweepy

In [2]:
consumer_key = 'M6OkpsVkxMo1m4oEpcKrxTG9L'
consumer_secret = 'huUxJYdPoddEkvRrmDOFQIuHspkBERTCshx2J5tcj7FeAFdgNp'
access_token = '13101632-jfzgS37obVEw5vEQhkg3iHuMSgZFwAnLz55OZcVyi'
access_token_secret = 'CeoEHGH6fzrFH1PbXxSwCvmL04rD6nQElJzKgMnAj9AY9'

In [3]:
autorizar = tweepy.OAuthHandler(consumer_key, consumer_secret)
autorizar.set_access_token(access_token, access_token_secret)

In [4]:
api = tweepy.API(autorizar)
print(api)


<tweepy.api.API object at 0x04739F70>

Exercício 1 - Utilizando o método update_with_media, realize a atualização do status utilizando a imagem fia.jpg disponível na pasta da aula.

Imprima com o status "Programação com Python e Twitter na FIA!"

In [7]:
retorno = api.update_with_media(filename='fia.jpg',status='Test. Upload media via python')

In [17]:
print(retorno.text)


Test. Upload media via python https://t.co/zMcEN0G6HZ

Exercício 2 - Salve o retorno do tweet do exercício anterior e imprima as seguintes informações:

* tweet
    * id
    * created_at
    * lang
    * text
* user
    * screen_name,
    * friends_count
    * time_zone

Por fim, remova o tweet, utilizando o método destroy_status.


In [9]:
print(retorno.id)
print(retorno.created_at)
print(retorno.lang)
print(retorno.text)


759198031828967424
2016-07-30 01:24:50
en
Test. Upload media via python https://t.co/zMcEN0G6HZ

In [10]:
print(retorno.user.screen_name)
print(retorno.user.friends_count)
print(retorno.user.time_zone)


rubensfernando
798
Brasilia

In [11]:
retornoDestroy = api.destroy_status(retorno.id)

Exercício 3 - Utilizando o método home_timeline(), recupere os 10 tweets atuais. Para cada um desses tweets, imprima:

* o screen_name
* o texto do tweet
* o id do usuário

In [12]:
home = api.home_timeline(count=10)

In [16]:
for i, tweet in enumerate(home):
    print(tweet.user.screen_name)
    print(tweet.text)
    print(tweet.user.id)
    print('\n')


Gizmodo
Look up, guys. It's the Delta Aquarids https://t.co/ijjAohtPT1 https://t.co/4rnsnI9XMq
2890961


Estadao
Demora no impeachment prejudica o País, diz Temer https://t.co/kUMBj1VSaM
9317502


JornalOGlobo
Capitão da seleção: de Preguinho a Bellini, Mauro, C. Alberto, Dunga, Cafu e Neymar. https://t.co/yzufEQ1jUQ https://t.co/bNoQnMayio
54341363


Gizmodo
Doughnut-flavored soda will make your dentist very rich https://t.co/xDENR4TljA https://t.co/b5ds4YFcZE
2890961


Reuters
Scots back remaining in UK despite Brexit vote: poll https://t.co/xiKav2j9bC https://t.co/VvTv65KnFu
1652541


viaSimonRomero
Lula, Brazil’s Ex-President, Will Face Trial on Obstruction Charges https://t.co/EiGIqPiJqN
122792963


wallacetim
First homegrown cases of Zika announced today in Fla. @iarynam &amp; @rudyomri offer this update https://t.co/AYevieyJGo https://t.co/qOKB7LsSE1
50387337


FiveThirtyEight
Cities in Southern California can't escape the fire at their door: https://t.co/wnyl1A3IPc https://t.co/rw2QlZN1Ug
2303751216


BicyclingMag
I actually got my stolen bike back — here's how: https://t.co/SCiQpYHwbv https://t.co/6i9uPlPpAY
17900130


vine
Impression game 💪 ....? More @ColesTwitt3r on Creator Spotlight: https://t.co/W7HSTsnSCk https://t.co/80Rl0YxJVt
586671909


Exercício 4 - Para cada tweet do exercício anterior, utilize o id do usuário e imprima o texto dos 5 primeiros tweets de cada um dos 10 usuários (user_timeline).


In [ ]:
for i, user in enumerate(home):

In [20]:
help(api.user_timeline)


Help on function _call in module tweepy.binder:

_call(*args, **kwargs)


In [ ]: