-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
89 lines (68 loc) · 2.36 KB
/
bot.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import tweepy
import requests
from secrets import *
from time import sleep
#OAuthHandler instance
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
# API instance
api = tweepy.API(auth)
#Creating a user class
class Individual:
def __init__(self, name):
mostrecenttweet = api.user_timeline(name)[0]
self.data = mostrecenttweet
self.mostrecenttweet = mostrecenttweet.text
self.id = mostrecenttweet.id
self.name = name
self.lasttweet = ''
def modify_last(self,last):
self.lasttweet = last
def modify_recent(self,recent):
self.mostrecenttweet = recent
def modify_id(self, stat_id):
self.id = stat_id
def classCreation(list):
people = []
for person in list:
user = Individual(person)
people.append(user)
return people
#analyze if the tweet is a retweet or a reply to a tweet
def scan_tweet(tweet):
if (tweet.in_reply_to_status_id is None):
try:
if(tweet.retweeted_status):
return False
except AttributeError:
return True
return False
def runTime(follow):
while True:
try:
for follower in follow:
# print('Last Tweet: '+ follower.lasttweet)
# print('Most Recent Tweet: '+follower.mostrecenttweet)
if follower.mostrecenttweet != follower.lasttweet:
if scan_tweet(follower.data):
api.retweet(follower.id)
print('Tweeted')
else:
print('Its a retweet or a reply')
# updates lasttweet to the most recent tweet
follower.modify_last(follower.mostrecenttweet)
#fetching the most recent tweet again
update = api.user_timeline(follower.name)[0]
follower.modify_recent(update.text)
follower.modify_id(update.id)
sleep(2)
except tweepy.TweepError as e:
print(e)
except AttributeError:
sleep(5)
print("sleeping")
print('\n')
sleep(60 * 5) # Sleep for 5 seconds
following = ['VitalikButerin','SatoshiLite','coindesk','rogerkver','brian_armstrong']
individuals = classCreation(following)
runTime(individuals)