forked from banool/recreation-gov-campsite-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifier.py
45 lines (38 loc) · 1.31 KB
/
notifier.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
import random
import sys
from camping import SUCCESS_EMOJI
from twitter_credentials import twitter_credentials as tc
import twitter
MAX_TWEET_LENGTH = 279
# Janky simple argument parsing.
if len(sys.argv) != 2:
print("Please provide the user you want to tweet at!")
sys.exit(1)
user = sys.argv[1].replace("@", "")
available_site_strings = []
for line in sys.stdin:
line = line.strip()
if SUCCESS_EMOJI in line:
name = " ".join(line.split(":")[0].split(" ")[1:])
available = line.split(":")[1][1].split(" ")[0]
s = "{} site(s) available in {}".format(available, name)
available_site_strings.append(s)
if available_site_strings:
api = twitter.Api(
consumer_key=tc["consumer_key"],
consumer_secret=tc["consumer_secret"],
access_token_key=tc["access_token_key"],
access_token_secret=tc["access_token_secret"],
)
tweet = "@{}, there are campsites available! 🏕🏕🏕\n{}".format(
user,
"\n".join(available_site_strings),
)
tweet += "\n" + "🏕" * random.randint(5, 20) # To avoid duplicate tweets.
tweet = tweet[:MAX_TWEET_LENGTH]
resp = api.PostUpdate(tweet)
api.CreateFavorite(resp)
print("The following was tweeted: ")
print(tweet)
else:
print("No campsites available, not tweeting 😞")