-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTwitter.py
43 lines (36 loc) · 1.37 KB
/
Twitter.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
#You will need to PIP INSTALL tweepy for this to work and also create a twitter API. Run this on your own machine, not in this Repl.
import tweepy
import time
consumer_key = 'YVsDSzGglc1I1750qc7Jvp8TY'
consumer_secret = 'swq47zxZ64GCDSyZdTYPIKlTj6MICXKAjrFa18bIVeEbacR5LR'
access_token = '1086535907170119680-rXW85WrFgGI50S5x67KpUufdyCYRHl'
access_token_secret = 'Jiqwevy0MRwrdiWkKn07055sN4x8y53JEBRiCJrPnAb8N'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
user = api.me()
print (user.name) #prints your name.
print (user.screen_name)
print (user.followers_count)
search = "zerotomastery"
numberOfTweets = 2
def limit_handle(cursor):
while True:
try:
yield cursor.next()
except tweepy.RateLimitError:
time.sleep(1000)
#Be nice to your followers. Follow everyone!
for follower in limit_handle(tweepy.Cursor(api.followers).items()):
if follower.name == 'Usernamehere':
print(follower.name)
follower.follow()
# Be a narcisist and love your own tweets. or retweet anything with a keyword!
for tweet in tweepy.Cursor(api.search, search).items(numberOfTweets):
try:
tweet.favorite()
print('Retweeted the tweet')
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break