/
sql_selects.py
executable file
·168 lines (120 loc) · 4.2 KB
/
sql_selects.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
__author__ = 'jbosley2'
import sql_settings as SQLS
def select_future_deliveries():
info = []
info_get = SQLS.db_fetch(
"select * from reservations where DATE(resStart) = CURDATE() AND deliveredBy = 'NA' ORDER BY resStart;")
try:
for el in info_get:
for ell in el:
info.append(str(ell))
info.append("|")
info.append("%")
info.pop(-1)
if info[-1] == "|":
info.pop(-1)
except :
# If there are no deliveries for the day, send this back :
info.append("NA")
SQLS.output_update_to_screen("Received a request for today's deliveries . . . . . ")
return info
def select_past_deliveries():
info = []
info_get = SQLS.db_fetch("SELECT * FROM reservations WHERE timeDelivered != '0000-00-00 00:00:00' AND timePickedup \
= '0000-00-00 00:00:00' AND DATE(resEnd) <= CURDATE() ORDER BY resEnd;")
# "SELECT * FROM reservations WHERE timeDelivered != '0000-00-00 00:00:00' AND timePickedup \
# = '0000-00-00 00:00:00' AND resEnd <= NOW() ORDER BY resEnd;"
try:
for el in info_get:
for ell in el:
info.append(str(ell))
info.append("|")
info.append("%")
info.pop(-1)
except:
info.append("NA")
SQLS.output_update_to_screen("Request for today's pickups . . . . . . . . . . . . . ")
return info
def select_links():
info = []
info_get = SQLS.db_fetch("SELECT * FROM repeated ;")
try:
for el in info_get:
for ell in el:
info.append(str(ell))
info.append("|")
info.append("%")
info.pop(-1)
except:
info.append("NA")
SQLS.output_update_to_screen("Received a request for linked items . . . . . . . ")
return info;
def select_inventory():
info = []
info_get = SQLS.db_fetch("SELECT * from inventory ORDER BY title;")
try:
for el in info_get:
for ell in el:
info.append(str(ell).replace('\n', ' '))
info.append("|")
info.append("%")
info.pop(-1)
except :
info.append("NA")
SQLS.output_update_to_screen("Received a request for inventory items . . . . . . . ")
return info
def select_schedule():
info = []
info_get = SQLS.db_fetch("SELECT inventoryItemID, datesUnavailable from inventorySchedule;")
try:
for el in info_get:
for ell in el:
info.append(str(ell))
info.append(", ")
info.append("%")
info.pop(-1)
except:
info.append("NA")
SQLS.output_update_to_screen("Received a request for schedule . . . . . . . ")
return info
def select_rooms():
info = []
info_get = SQLS.db_fetch("SELECT * from rooms ORDER BY roomName;")
try:
for el in info_get:
for ell in el:
info.append(str(ell))
info.append("|")
info.append("%")
info.pop(-1)
except :
info.append("NA")
SQLS.output_update_to_screen("Received a request for room names . . . . . . . ")
return info
# ---- SPECIFIC SELECTS ----
def select_reservation_by_id(data):
info = []
for el in SQLS.db_fetch("SELECT * FROM reservations WHERE resId = '%s';" % str(data))[0]:
info.append(str(el))
info.append("|")
info.pop(-1)
SQLS.output_update_to_screen("Received a request reservation by ID . . . . . . . ")
return info
def select_reservations_by_date(date):
info = []
reservations = SQLS.db_fetch(
"SELECT * FROM reservations WHERE DATE(resStart) = DATE('%s');" % date
)
try:
for el in reservations:
for ell in el:
info.append(str(ell))
info.append("|")
info.append("%")
info.pop(-1)
if info[-1] == "|":
info.pop(-1)
except :
# If there are no deliveries for the day, send this back :
info.append("NA")
return info