-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
109 lines (94 loc) · 3.98 KB
/
main.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
import webapp2
import csv
import os
import time
from google.appengine.ext.webapp import template
class MainPage(webapp2.RequestHandler):
def get(self):
#self.response.headers['Content-Type'] = 'text/plain'
#self.response.write('Hello, World!')
template_values = {
'greetings': 'greetings',
'url': 'url',
'url_linktext': 'url_linktext',
'title': 'Booloo Export',
}
path = os.path.join(os.path.dirname(__file__), 'templates/start.html')
self.response.out.write(template.render(path, template_values))
class ProcessPage(webapp2.RequestHandler):
def post(self):
## Load all files into lists
teams_file_list = self.file_to_list(self.request.get('teamsFile'))
source_file_list = self.file_to_list(self.request.get('sourceFile'))
total_file_list = self.file_to_list(self.request.get('totalFile'))
## Split file lists into group lists
## 'key in CSV file' --> filename of JSON output
# (teams_file_list) 'Sumo' --> sumo
# (teams_file_list) 'Reps' --> reps
# (teams_file_list) 'QA' --> qa
# (teams_file_list) 'Firefox OS' --> firefoxos
# (teams_file_list) 'Firefox for Android' --> firefoxforandroid
# (teams_file_list) 'Firefox' --> firefox
# (source_file_list) 'bugzilla' --> bugzilla
# (source_file_list) 'github' --> github
# (total_file_list) 'all' --> all
final_data = []
final_data.append(self.transform_data(teams_file_list, 0, 'Sumo', 'sumo'))
final_data.append(self.transform_data(teams_file_list, 0, 'Reps', 'reps'))
final_data.append(self.transform_data(teams_file_list, 0, 'QA', 'qa'))
final_data.append(self.transform_data(teams_file_list, 0, 'Firefox OS', 'firefoxos'))
final_data.append(self.transform_data(teams_file_list, 0, 'Firefox For Android', 'firefoxforandroid'))
final_data.append(self.transform_data(teams_file_list, 0, 'Firefox', 'firefox'))
final_data.append(self.transform_data(source_file_list, 0, 'bugzilla', 'bugzilla'))
final_data.append(self.transform_data(source_file_list, 0, 'github', 'github'))
final_data.append(self.transform_data(total_file_list, -1, 'NOKEY', 'all'))
template_values = {
'data':final_data,
}
path = os.path.join(os.path.dirname(__file__), 'templates/finish.html')
self.response.out.write(template.render(path, template_values))
def file_to_list(self, fle):
ret = []
rownum = 0
reader = csv.reader(fle.split("\n"))
for row in reader:
if rownum == 0:
header = row
else:
ret.append(row)
rownum += 1
return ret
def transform_data(self, src, key_pos, key, dest):
# Create list
filtered_list = []
for row in src:
if len(row) > 0:
if row[key_pos] == key or key == 'NOKEY':
filtered_list.append(row)
filtered_list.reverse()
## GAE doesn't let you write to files /facepalm
#with open(dest,"w") as f:
# f.write('test')
# f.close()
#for each
return_json = ""
i = 0
return_json += '['
for row in filtered_list:
add_comma = ","
if i == 0:
add_comma = ""
#September 29, 2014
try:
dt = time.strptime(row[key_pos+1], "%B %d, %Y")
week_date_string = time.strftime("%Y-%m-%d", dt)
return_json += add_comma + '{"wkcommencing":"' + week_date_string + '","totalactive":' + row[key_pos+3] + ',"new":' + row[key_pos+2] + '}'
i += 1
except ValueError:
continue
return_json += "]"
return [return_json,dest]
application = webapp2.WSGIApplication([
('/', MainPage),
('/process', ProcessPage)
], debug=True)