This repository has been archived by the owner on May 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
77 lines (51 loc) · 1.75 KB
/
run.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
import tweepy
import time
from dotenv import load_dotenv
import os
import get_dates
# replies with co2 values
# "borrowed" from https://stackoverflow.com/a/59978258/2327328
def create_api():
load_dotenv()
consumer_key = os.environ.get("TWITTER_CONSUMER_KEY")
consumer_secret = os.environ.get("TWITTER_CONSUMER_SECRET")
access_token = os.environ.get("TWITTER_ACCESS_TOKEN")
access_token_secret = os.environ.get("TWITTER_ACCESS_TOKEN_SECRET")
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=False, wait_on_rate_limit_notify=False)
api.verify_credentials()
return api
def check_mentions(api, since_id):
data = None
latest = None
new_since_id = since_id
for tweet in tweepy.Cursor(api.mentions_timeline, since_id=since_id).items():
if data is None:
data, latest = get_dates.load_data()
#tweepy.Cursor(api.mentions_timeline, since_id=since_id).items()
new_since_id = max(tweet.id, new_since_id)
if tweet.in_reply_to_status_id is not None:
continue
#if not tweet.user.following:
# tweet.user.follow()
#reply = '@'+tweet.user.screen_name + ' ' + get_dates.main(tweet.text, data, latest)
reply = get_dates.main(tweet.text, data, latest)
print('LOGGING: '+str(tweet.id))
try:
api.update_status(status=reply, in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
except:
pass # avoid duplicate replies
return new_since_id
def main():
api = create_api()
with open('since.txt','r') as fp:
since_id = int(fp.read())
# debugging
#since_id = 1
#print(since_id)
since_id = check_mentions(api, since_id)
with open('since.txt','w') as fp:
fp.write(str(since_id))
if __name__ == "__main__":
main()