-
Notifications
You must be signed in to change notification settings - Fork 0
/
recurbot.py
89 lines (65 loc) · 3.73 KB
/
recurbot.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
#!/usr/bin/python
import argparse, datetime, json
from helpers import *
def morning(recurringEventList, recurringEvents, recurringEventLog, recurringLogged):
"""The job of morning is to simply look at all tasks on deck today, and remind the user
of said tasks."""
out = "Good morning! Here are the recurring tasks on deck for you today...\n"
list_eventName = 0
list_shorthandEventName = 1
list_recurrence = 2
list_morningReminder = 3
list_eveningReminder = 4
for event in recurringEvents:
if recurringEventIsToday(event[list_recurrence]):
out += event[list_eventName] + "\n"
print (out)
return out
def evening(recurringEventList, recurringEvents, recurringEventLog, recurringLogged):
"""More than just looking at the tasks on deck today, we need to see which of them have
not been fulfilled yet."""
out = "Hey-o, eveningbot here! Here's where today's recurring tasks stand...\n"
roundup = dailyTaskRoundup(recurringEvents, recurringLogged).items()
for task, status in roundup:
if status:
out += "{task}: Complete\n".format(task = task)
else:
out += "{task}: Incomplete\n".format(task = task)
print (out)
return out
def midnight(recurringEventList, recurringEvents, recurringEventLog, recurringLogged):
"""Mark today's tasks as met or missed so that an accurate streak count can be made."""
datetime_string = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
for task, status in dailyTaskRoundup(recurringEvents, recurringLogged).items():
if status == False:
print ("Marking as missed: ", task)
recurringEventLog.append_row([task, datetime_string, "missed"])
else:
print ("Not marking as missed: ", task)
if __name__ == "__main__":
# Command line params mainly exist to allow cron jobs to know where the config files are located
parser = argparse.ArgumentParser()
parser.add_argument("--twiliosecrets", "-t", nargs='?', default="twilio-secrets.json",
help="Absolute path to the Twilio secrets file if running from, say, a Cron job.")
parser.add_argument("--gdrivesecrets", "-g", nargs='?', default="client-secrets.json",
help="Absolute path to the Gdrive secrets file if running from, say, a Cron job.")
parser.add_argument("botmode", nargs='?', default="twilio-secrets.json",
help="'morning', 'evening', or 'midnight'.")
args = parser.parse_args()
# get twilio and gspread set up
with open(args.twiliosecrets, "r") as secrets_file:
secrets = json.load(secrets_file)
twilioClient = Client(secrets["twilio-sid"], secrets["twilio-token"])
gClient = client = openSheet(args.gdrivesecrets)
recurringEventList = gClient.open("Recurring Event List").sheet1
recurringEvents = recurringEventList.get_all_values()
recurringEventLog = gClient.open("Recurring Event Log").sheet1
recurringLogged = recurringEventLog.get_all_values()
if args.botmode == "morning":
sendTwilioTextMessage(twilioClient, secrets["from"], secrets["to"], morning(recurringEventList, recurringEvents, recurringEventLog, recurringLogged))
elif args.botmode == "evening":
sendTwilioTextMessage(twilioClient, secrets["from"], secrets["to"], evening(recurringEventList, recurringEvents, recurringEventLog, recurringLogged))
elif args.botmode == "midnight":
midnight(recurringEventList, recurringEvents, recurringEventLog, recurringLogged)
else:
print ("Bot mode ('morning', 'evening', or 'midnight' must be specified using the --botmode argument!")