-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
277 lines (239 loc) · 8.3 KB
/
app.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
from flask import Flask, request, render_template, send_file
import urllib.request
import requests
import string
import re
import json
import base64
import csv
import codecs
import os, errno
from werkzeug.utils import secure_filename
from flask_cors import CORS
app = Flask(__name__, template_folder = os.getcwd() + '/forms')
CORS(app)
@app.route("/")
def hello():
with open(os.getcwd() + '/application/data.csv', newline='') as myFile1:
reader1 = csv.reader(myFile1)
for row in reader1:
print(row)
with open(os.getcwd() + '/application/hardware.csv', newline='') as myFile2:
reader2 = csv.reader(myFile2)
for row in reader2:
print(row)
with open(os.getcwd() + '/application/sponsors.csv', newline='') as myFile3:
reader3 = csv.reader(myFile3)
for row in reader3:
print(row)
with open(os.getcwd() + '/application/judges.csv', newline='') as myFile4:
reader4 = csv.reader(myFile4)
for row in reader4:
print(row)
with open(os.getcwd() + '/application/goals.csv', newline='') as myFile5:
reader5 = csv.reader(myFile5)
for row in reader5:
print(row)
return "hey it's me"
@app.route("/users")
def newSheet():
name = request.args.get("name")
email = request.args.get("email")
school = request.args.get("school")
row = [name, email, school]
with open(os.getcwd() + '/application/data.csv', "a") as f:
writer = csv.writer(f)
writer.writerow([''.join([name, " "]), ''.join([email, " "]), ''.join([school, " ,,"])])
#array1.append(''.join([name, " "]) + ''.join([email, " "]) + ''.join([school, " "]))
return "Users"
@app.route("/hardware")
def newSheet2():
deviceName = request.args.get("deviceName")
loanee = request.args.get("loanee")
cost = request.args.get("cost")
row = [deviceName, loanee, cost]
with open(os.getcwd() + '/application/hardware.csv', "a") as f:
writer = csv.writer(f)
writer.writerow([''.join([deviceName, " "]), ''.join([loanee, " "]), ''.join([cost, " ,,"])])
#array2.append(''.join([deviceName, " "]) + ''.join([loanee, " "]) + ''.join([cost, " "]))
return "Hardware"
@app.route("/sponsors")
def newSheet3():
companyName = request.args.get("companyName")
status = request.args.get("status")
proposal = request.args.get("proposal")
notes = request.args.get("notes")
row = [companyName, status, proposal, notes]
with open(os.getcwd() + '/application/sponsors.csv', "a") as f:
writer = csv.writer(f)
writer.writerow([''.join([companyName, " "]), ''.join([status, " "]), ''.join([proposal, " "]), ''.join([notes, " ,,"])])
return "Sponsors"
@app.route("/judges")
def newSheet4():
judgeName = request.args.get("judgeName")
projectName = request.args.get("projectName")
c1Grade = request.args.get("c1Grade")
c1Notes = request.args.get("c1Notes")
c2Grade = request.args.get("c2Grade")
c2Notes = request.args.get("c2Notes")
c3Grade = request.args.get("c3Grade")
c3Notes = request.args.get("c3Notes")
c4Grade = request.args.get("c4Grade")
c4Notes = request.args.get("c4Notes")
c5Grade = request.args.get("c5Grade")
c5Notes = request.args.get("c5Notes")
row = [judgeName, projectName, c1Grade, c1Notes, c2Grade, c2Notes, c3Grade, c3Notes, c4Grade, c4Notes, c5Grade, c5Notes]
with open(os.getcwd() + '/application/judges.csv', "a") as f:
writer = csv.writer(f)
writer.writerow([''.join([judgeName, " "]), ''.join([projectName, " "]), ''.join([c1Grade, " "]), ''.join([c1Notes, " "]), ''.join([c2Grade, " "]), ''.join([c2Notes, " "]), ''.join([c3Grade, " "]), ''.join([c3Notes, " "]), ''.join([c4Grade, " "]), ''.join([c4Notes, " "]), ''.join([c5Grade, " "]), ''.join([c5Notes, " ,,"])])
return "judges"
@app.route("/goals")
def newSheet5():
goals = request.args.get("date")
emailList = request.args.get("milestone")
row = [goals, emailList]
with open(os.getcwd() + '/application/goals.csv', "a") as f:
writer = csv.writer(f)
writer.writerow([''.join([goals, " "]), ''.join([emailList, " "]), ''.join(["N/A ,,"])])
return "goals"
@app.route("/output1")
def output1():
with open(os.getcwd() + '/application/data.csv') as f:
s1 = f.read() + '\n'
return(s1)
@app.route("/output2")
def output2():
# asdf
with open(os.getcwd() + '/application/hardware.csv') as f:
s2 = f.read() + '\n'
return(s2)
@app.route("/output3")
def output3():
with open(os.getcwd() + '/application/sponsors.csv') as f:
s3 = f.read() + '\n'
return(s3)
@app.route("/output4")
def output4():
with open(os.getcwd() + '/application/judges.csv') as f:
s4 = f.read() + '\n'
return(s4)
@app.route("/output5")
def output5():
with open(os.getcwd() + '/application/goals.csv') as f:
s5 = f.read() + '\n'
return(s5)
@app.route("/output6")
def output6():
with open(os.getcwd() + '/application/logistics.csv') as f:
s5 = f.read() + '\n'
return(s5)
@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
new_rows = []
f = request.files['file']
directory = os.getcwd() + '/application/invoices/' + request.values['row']+ '/'
print(directory)
if (os.path.exists(directory)):
print("exists")
else:
os.makedirs(directory)
f.save(os.path.join(directory, secure_filename(f.filename)))
with open(os.getcwd() + '/application/sponsors.csv') as f:
reader = csv.reader(f)
for row in reader:
new_rows.append(row)
print(new_rows[int(request.values['row'])][4])
new_rows[int(request.values['row'])][4] = 'loading...'
print(new_rows[int(request.values['row'])][4])
with open(os.getcwd() + '/application/sponsors.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(new_rows)
return "file uploaded"
@app.route('/get_files')
def get_files():
folder = request.args.get('folder')
directory = os.getcwd() + '/application/invoices/' + folder
print(directory)
img_files = ''
for file in os.listdir(directory):
print(file)
if file.lower().endswith(('.png', '.jpg', '.jpeg', '.gif')):
print("YES")
img_files += ',' + file
else:
print("NO")
print(os.listdir(directory))
return img_files
@app.route('/change_milestone_status')
def change_milestone_status():
new_rows = []
row = request.args.get('row')
status = request.args.get('status')
with open(os.getcwd() + '/application/goals.csv') as f:
reader = csv.reader(f)
for row in reader:
new_rows.append(row)
print(new_rows[int(request.values['row'])][2])
new_rows[int(request.values['row'])][2] = status
print(new_rows[int(request.values['row'])][2])
with open(os.getcwd() + '/application/goals.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(new_rows)
return "changed"
@app.route('/change_logistics')
def change_logistics():
new_rows = []
row = request.args.get('row')
status = request.args.get('status')
with open(os.getcwd() + '/application/logistics.csv') as f:
reader = csv.reader(f)
for row in reader:
new_rows.append(row)
print(new_rows[int(request.values['row'])-1][1])
new_rows[int(request.values['row'])-1][1] = status
print(new_rows[int(request.values['row'])-1][1])
with open(os.getcwd() + '/application/logistics.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(new_rows)
return "changed"
@app.route('/get_ranking')
def get_ranking():
new_rows = []
point_vals = []
unique_projects = []
with open(os.getcwd() + '/application/judges.csv') as f:
reader = csv.reader(f)
for row in reader:
if row[1] not in unique_projects:
unique_projects.append(row[1])
unique_projects.append(int(row[2]) + int(row[4]) + int(row[6]) + int(row[8]) + int(row[10]))
else:
unique_projects[unique_projects.index(row[1]) + 1] += int(row[2]) + int(row[4]) + int(row[6]) + int(row[8]) + int(row[10])
print(unique_projects)
return str(unique_projects)[1:-1]
@app.route("/sendEmail")
def send_simple_message():
name = request.args.get("name")
email = request.args.get("email")
subject = request.args.get("subject")
textLine = request.args.get("text")
return requests.post(
"https://api.mailgun.net/v3/sandboxc5380f848a684d4aa86069c1308d4884.mailgun.org/messages",
auth=("api", "key-ef2d27e2ebe2754a5335866944846055"),
data={"from": "PalyHacks <[email protected]>",
"to" : name + " <" + email + ">",
"subject" : subject,
"text" : textLine,
})
@app.route('/judge_form')
def judge_form():
return render_template('judge.html')
@app.route('/user_form')
def user_form():
return render_template('newUser.html')
@app.route('/hardware_form')
def hardware_form():
return render_template('hardware.html')
if __name__ == '__main__':
app.run()