-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.py
30 lines (21 loc) · 1.08 KB
/
timer.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
#!/usr/bin/python3
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from datetime import datetime, timedelta
def timer(body):
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client-secrets.json', scope)
client = gspread.authorize(creds)
try:
minutes = int(body.split(' ')[1])
except IndexError:
return "Please specify a time in minutes! Syntax: 'Timer [minutes] [expiration message]"
try:
message = body.split(' ', 2)[2]
except IndexError:
return "Please specify a message to be sent to you upon expiration! Syntax: 'Timer [minutes] [expiration message]"
now = datetime.now()
expirationTime = now + timedelta(minutes = minutes)
sheet = client.open("Timers").sheet1
sheet.append_row([minutes, message, str(expirationTime), 'active'])
return "You have requested a timer for {minutes} minutes, with the message '{message}'".format(minutes = minutes, message = message)