-
Notifications
You must be signed in to change notification settings - Fork 6
/
shuttle.py
50 lines (32 loc) · 1.38 KB
/
shuttle.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
def get_shuttle(message_text):
from datetime import datetime, timedelta
from db_operations.connect import connect
import os
origin_asked = message_text[8:]
schedule_day = ''
weekdays = ['monday', 'tuesday', 'wednesday', 'thursday']
holidays = ['saturday', 'sunday']
# Get current time - time at which message has been received by this script
my_time = datetime.utcnow() + timedelta(hours=5) + timedelta(minutes=30)
my_day = my_time.strftime('%A').lower()
if my_day in weekdays:
schedule_day = 'weekday'
elif my_day in holidays:
schedule_day = 'holiday'
else:
schedule_day = 'friday'
# get schedule from db
client = connect(os.environ["MONGODB_URI"] if os.environ.get("MONGODB_URI") else "mongodb://localhost:27017/ashoka-bot")
db = client.get_default_database()
shuttle_schedule = db.shuttle_schedules.find_one({"origin": origin_asked.lower()})
route = shuttle_schedule['route']
today_timings = shuttle_schedule['schedule'][schedule_day]
phone = shuttle_schedule['phone']
# Start generating return message
return_message = "The request was received on {0}.\n\nToday, shuttles will run from {1} at:\n{2}".format(my_time.strftime('%A, %H:%M'), route, today_timings)
if phone != '':
return_message += "\n\nGuard at {0}: {1}".format(origin_asked, phone)
print return_message
# Return the message to callee
return return_message
# get_shuttle('SHUTTLE METRO')