-
Notifications
You must be signed in to change notification settings - Fork 0
/
Holabot.py
93 lines (79 loc) · 4.18 KB
/
Holabot.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
90
91
92
93
import tweepy
import time
print("\n\nHelloWorld! I am BOT. My name is Hola\n\n")
CONSUMER_KEY = 'XXXXXX'
CONSUMER_SECRET = 'XXXXXX'
ACCESS_KEY = 'XXXXXX'
ACCESS_SECRET = 'XXXXXX'
auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY,ACCESS_SECRET)
api = tweepy.API(auth)
def retrieve_last_tweet_id(file_name):
f_read = open(file_name, 'r')
last_tweet_id = int(f_read.read().strip())
f_read.close()
return last_tweet_id
def store_last_tweet_id(last_tweet_id,file_name):
f_write = open(file_name,'w')
f_write.write(str(last_tweet_id))
f_write.close()
return
# REPLYING TO TWEETS CONATAIN HEY BY MENTIONING ME
def reply_to_tweets():
print("retriveing and replying tweets")
last_tweet_id = retrieve_last_tweet_id('last_tweet_id.txt')
mentions = api.mentions_timeline()
#or 'hi'or "hy" or "hello" or "hola"
for mention in reversed(mentions):
print(str(mention.id)+ '--' + mention.text)
last_tweet_id = mention.id
store_last_tweet_id(last_tweet_id,'last_tweet_id.txt')
lowermention = mention.text.lower()
if('hey' in lowermention):
print('\n\nHey! I found #hey...\n')
api.update_status("@"+ mention.user.screen_name + " Hey There!! I am Hola bot." , mention.id)
print("\ndone replying to",mention.user.screen_name ," Id =", mention.id,'\n')
elif('hi' in lowermention):
print('\n\nHey! I found #hey...\n')
api.update_status("@"+ mention.user.screen_name + " Hi There! I am Hola bot" , mention.id)
print("\ndone replying to",mention.user.screen_name ," Id =", mention.id,'\n')
elif('hello' in lowermention):
print('\n\nHey! I found #hey...\n')
api.update_status("@"+ mention.user.screen_name + " Hello There! I am Hola bot" , mention.id)
print("\ndone replying to",mention.user.screen_name ," Id =", mention.id,'\n')
elif('hy' in lowermention):
print('\n\nHey! I found #hey...\n')
api.update_status("@"+ mention.user.screen_name + " Hy There! I am Hola bot" , mention.id)
print("\ndone replying to",mention.user.screen_name ," Id =", mention.id,'\n')
elif('hii' in lowermention):
print('\n\nHey! I found #hey...\n')
api.update_status("@"+ mention.user.screen_name + " Hii There! I am Hola bot" , mention.id)
print("\ndone replying to",mention.user.screen_name ," Id =", mention.id,'\n')
elif('hola' in lowermention):
print('\n\nHey! I found #hey...\n')
api.update_status("@"+ mention.user.screen_name + " Hey There! I am Hola bot. Thanks For mentioning me" , mention.id)
print("\ndone replying to",mention.user.screen_name ," Id =", mention.id,'\n')
elif('helloworld' in lowermention):
print('\n\nHey! I found #hey...\n')
api.update_status("@"+ mention.user.screen_name + " Hey World! I am Hola bot" , mention.id)
print("\ndone replying to",mention.user.screen_name ," Id =", mention.id,'\n')
else:
print("No Greating")
api.update_status("@"+ mention.user.screen_name + " HELLOWORLD! I am Hola bot" , mention.id)
print("\ndone replying to",mention.user.screen_name ," Id =", mention.id,'\n')
def reply_to_home_tweet():
print("retriveing and replying tweets")
last_tweet_id = retrieve_last_tweet_id('last_tweet_id.txt')
home_tweets = api.home_timeline()
for home_tweet in home_tweets:
print(str(home_tweet.id)+ '--' + home_tweet.text)
last_tweet_id = home_tweet.id
store_last_tweet_id(last_tweet_id,'last_tweet_id.txt')
api.update_status("@"+ home_tweet.user.screen_name + " #HELLOWORLD" , home_tweet.id)
print("\ndone replying to",home_tweet.user.screen_name ," Id =", home_tweet.id,'\n')
if __name__ == "__main__":
#IT WILL AUTOMATICALLY REPLY TO ALL LATEST TWEETS WHO MENTION YOU
reply_to_tweets()
#IT WILL AUTOMATICALLY REPLY TO ALL LATEST TWEETS IN YOUR HOME PAGE
reply_to_home_tweet()
time.sleep(15)