-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_store_open.py
104 lines (95 loc) · 4.27 KB
/
check_store_open.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
#Following functions written by LEE LUCIUS
def Operating_Hours():
myfile= open('OperatingTimes.txt','r') #open file for reading
operating_time=myfile.readlines() #add each line in the file to a list
full_times = [operating_time[i:i+5] for i in range(0, len(operating_time), 5)]
#split list into sub-list of 5 elements, each sub-list represent each store
Chinese_times=full_times[0] #set variable for each sub-list for clarity
Malay_times=full_times[1]
Indian_times=full_times[2]
Italian_times=full_times[3]
myfile.close() #close file
return ["Open 24/7",Chinese_times,Malay_times,Indian_times,Italian_times]
def Stalls_Open(day,hour):
myfile= open('OperatingTimes.txt','r') #open file for reading
operating_time=myfile.readlines() #add each line in the file to a list
for i in range(len(operating_time)): #remove \n from each line
operating_time[i]=operating_time[i][:-1]
full_times = [operating_time[i:i+5] for i in range(0, len(operating_time), 5)]
#split list into sub-list of 5 elements, each sub-list represent each store
Chinese_times=full_times[0] #set variable for each sub-list for clarity
Malay_times=full_times[1]
Indian_times=full_times[2]
Italian_times=full_times[3]
myfile.close() #close file
def check_all_open(day,hour): #function to check if any store is open
#parameter day as Mon,Tue,Wed,Thu,Fri,Sat,Sun
#parameter hour using the 24 hour clock, eg. 7pm as 1900
Chinese_open=check_chinese_open(day,hour)
Malay_open=check_malay_open(day,hour)
Indian_open=check_indian_open(day,hour)
Italian_open=check_italian_open(day,hour)
List_open= ["McDonalds\n"]
if Chinese_open:
List_open.append("Chinese Stall\n")
if Malay_open:
List_open.append("Malay Stall\n")
if Indian_open:
List_open.append("Indian Stall\n")
if Italian_open:
List_open.append("Italian Stall\n")
return List_open
def check_chinese_open(day,hour): #function to check if chinese store is open, same process used for other stores
hour=int(hour) #convert hours to integer
if day in Chinese_times[1]: #check if it is a weekday
if hour >= int(Chinese_times[2][0:4]) and hour <= int(Chinese_times[2][5:9]):
return True #return True if hour given is within opening hours
else:
return False
elif day in Chinese_times[3]: #check if it is a weekend
if hour >= int(Chinese_times[4][0:4]) and hour <= int(Chinese_times[4][5:9]):
return True #return True if hour given is within opening hours
else:
return False
else:
return False
def check_malay_open(day,hour):
if day in Malay_times[1]:
if hour >= int(Malay_times[2][0:4]) and hour <= int(Malay_times[2][5:9]):
return True
else:
return False
elif day in Malay_times[3]:
if hour >= int(Malay_times[4][0:4]) and hour <= int(Malay_times[4][5:9]):
return True
else:
return False
else:
return False
def check_indian_open(day,hour):
if day in Indian_times[1]:
if hour >= int(Indian_times[2][0:4]) and hour <= int(Indian_times[2][5:9]):
return True
else:
return False
elif day in Indian_times[3]:
if hour >= int(Indian_times[4][0:4]) and hour <= int(Indian_times[4][5:9]):
return True
else:
return False
else:
return False
def check_italian_open(day,hour):
if day in Italian_times[1]:
if hour >= int(Italian_times[2][0:4]) and hour <= int(Italian_times[2][5:9]):
return True
else:
return False
elif day in Italian_times[3]:
if hour >= int(Italian_times[4][0:4]) and hour <= int(Italian_times[4][5:9]):
return True
else:
return False
else:
return False
return check_all_open(day,hour)