-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_timeline.py
45 lines (31 loc) · 1.35 KB
/
get_timeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import tweepy
import time
import sys
# NOTE: I put my keys in the credentials.py to separate them
# from this main file.
# Please refer to credentials.py to see the format.
from credentials import twitter_bot_keys
# NOTE: flush=True is just for running this script
print('\nThis is my twitter bot: BerryNews Bot - BNB.\nStarted running...', flush=True)
auth = tweepy.OAuthHandler(twitter_bot_keys['API Key'], twitter_bot_keys['API Key Secret'])
auth.set_access_token(twitter_bot_keys['Access Token'], twitter_bot_keys['Access Token Secret'])
api = tweepy.API(auth)
try:
api.verify_credentials()
print("Authentication OK\n")
except:
print("Error during authentication\n")
## PRINTING OWN TIMELINE
print('### Printing own timeline:\n')
timeline = api.home_timeline(count=1)
for tweet in timeline:
time = tweet.created_at.strftime('%H:%M:%S %d-%m-%Y')
print(f"AT: {time}\nUSER ID: {tweet.user.id}\nUSER: {tweet.user.name}\nSAID: {tweet.text} \n")
print("############################################################\n")
print()
# PRINTING USER TIMELINE
print('### Printing user timeline:\n')
timeline = api.user_timeline(screen_name="b_tudorache", count=2)
for tweet in timeline:
print(f"USER {tweet.user.name} \nSAID {tweet.text} \nAT {tweet.created_at}\n")
print("############################################################\n")