-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar1.py
130 lines (118 loc) · 4.27 KB
/
calendar1.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#Calendar
from datetime import *
import time
from pytz import timezone
TIMEZONE = timezone('Australia/Sydney')
from get_dino import checkForDay
from bot_constants import week_days
#column_value = 0
'''
def getevent(day, message):
global week_days
current_day = datetime.now(TIMEZONE).weekday()
if "tomorrow" in message or "tmrw" in message or "tomoz" in message:
elif
'''
def getDay(message):
current_day = datetime.now(TIMEZONE).weekday()
x = datetime.now(TIMEZONE)
weekofterm = (int(x.strftime("%W"))-6) #ZERO WEEK HERE
day = "Today"
column_value = int(current_day) + 2
if "tomorrow" in message or "tmrw" in message or "tomoz" in message:
day = "Tomorrow"
#print(current_day)
if int(current_day) == 6: #if sunday
weekofterm+=1
column_value = 2 #sets column to monday the next week
else:
column_value = int(current_day) + 3
#print(column_value)
elif checkForDay(message):
print("day found")
#global week_days
if current_day > int(checkForDay(message)):
if weekofterm == 10:
print("end of term") #FIX this
else:
weekofterm+=1
current_day = int(checkForDay(message))
column_value = current_day + 2
day = str(week_days[int(checkForDay(message))])
else:
current_day = int(checkForDay(message))
column_value = current_day + 2
day = str(week_days[int(checkForDay(message))])
return current_day, day, weekofterm, column_value
def checkfornumber(message):
weeknumber = ""
if "one" in message or "1" in message:
weeknumber = 1
elif "two" in message or "2" in message:
weeknumber = 2
elif "three" in message or "3" in message:
weeknumber = 3
elif "four" in message or "4" in message:
weeknumber = 4
elif "five" in message or "5" in message:
weeknumber = 5
elif "six" in message or "6" in message:
weeknumber = 6
elif "seven" in message or "7" in message:
weeknumber = 7
elif "eight" in message or "8" in message:
weeknumber = 8
elif "nine" in message or "9" in message:
weeknumber = 9
elif "ten" in message or "10" in message:
weeknumber = 10
return weeknumber
###COLUMNS:
##0 - week
##1 - wholeweek
##2 - monday
##3 - tuesday
##4 - wednesday
##5 - thursday
##6 - friday
##7 - saturday
##8 - sunday
def get_events(message, con):
response = ""
# global weekofterm
# global column_value
# global day
try:
current_day, day, weekofterm, column_value = getDay(message)
if "week" in message:
cur = con.cursor()
getDay(message)
if checkfornumber(message): # checks if user is asking for a specific week
weekofterm = checkfornumber(message)
if "next" in message:
weekofterm+=1
cur.execute('''SELECT * FROM calendar WHERE week = %s''',str(weekofterm))
row = cur.fetchone()
headers = ["Whole Week: ","Monday: ", "Tuesday: ", "Wednesday: ", "Thursday: ", "Friday: " ,"Saturday: ", "Sunday: "]
response = response + f"Events in Week {weekofterm}:\n"
for i in range(1,9):
if str(row[i]) == "None": ### THIS WILL ALSO NEED TO BE CHANGED
response = response + headers[i-1] + "No Events" + "\n\n"
else:
response = response + headers[i-1] + row[i] + "\n\n"
else:
row = []
cur = con.cursor()
getDay(message)
cur.execute('''SELECT * FROM calendar WHERE week = %s''',str(weekofterm))
row = cur.fetchone()
#print(str(row) + "- ROW THING")
#print(str(weekofterm) + " week")
if str(row[column_value]) == "None": #this can be changed to "is None" next time
response = f"No events on {day}."
else:
response = response + f"Events on {day}: \n" + str(row[column_value])
except Exception as error:
print("Error: " + str(error) + "\n" + str(type(error)))
response = response + "Error in getting events: \n" + str(error)
return response