/
reply.py
56 lines (39 loc) · 1.58 KB
/
reply.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
# -*- coding: utf-8 -*-
import tweepy,random,time
#from our keys module (keys.py), import the keys dictionary
from replykeys import keys
from datetime import datetime,timedelta
from random import randint
CONSUMER_KEY = keys['consumer_key']
CONSUMER_SECRET = keys['consumer_secret']
ACCESS_TOKEN = keys['access_token']
ACCESS_TOKEN_SECRET = keys['access_token_secret']
argfile = str("liners.txt")
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
while True:
trends1 = api.trends_place(2379574) #WOE id for Chicago
hashtags = [x['name'] for x in trends1[0]['trends'] if x['name'].startswith('#')]
trend_hashtag = hashtags[0]
tweetSearchResults = api.search(q=trend_hashtag,count=50)
#list of specific strings we want to check for in Tweets
filename=open(argfile,'r')
f=filename.readlines()
filename.close()
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
for tweet in tweetSearchResults:
#print tweet
#print '\r\n'
sn = tweet.user.screen_name
message = f[randint(0,len(f)-1)]
m = "@{0}, {1} {2}".format(sn, message,trend_hashtag)
print m
#print '\r\n'
s = api.update_status(status=m, in_reply_to_status_id = tweet.id)
TimeToSleep = randint(120,360)
time.sleep(TimeToSleep)#Tweet every 2-4 minutes
TimeToSleep = randint(3600,4000)#wait 10-20 minutes to look for a new topic
time.sleep(TimeToSleep)#Tweet every 15 minutes