-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
122 lines (99 loc) · 3.42 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
110
111
112
113
114
115
116
117
118
119
120
121
122
import cgi
import datetime
import urllib
import webapp2
import json
import httplib
from google.appengine.ext import db
from google.appengine.api import users
import jinja2
import os
jinja_environment = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
class MainPage(webapp2.RequestHandler):
def get(self):
# guestbook_name=self.request.get('guestbook_name')
# greetings_query = Greeting.all().ancestor(
# guestbook_key(guestbook_name)).order('-date')
# greetings = greetings_query.fetch(10)
template_values = {
# 'greetings': greetings,
# 'url': url,
# 'url_linktext': url_linktext,
}
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))
class GetData(webapp2.RequestHandler):
def get(self):
# Process data
sex = self.request.get("sex")
# Get postcode from data set
if (sex == "both"):
self.response.write(Data.datas)
elif (sex == "male"):
self.response.write("[")
male_count = 0
for data in Data.datas:
if (data["Gender"] == "0"):
if (male_count != 0):
self.response.write(",")
self.response.write(data)
male_count = male_count + 1
self.response.write("]")
elif (sex == "female"):
self.response.write("[")
female_count = 0
for data in Data.datas:
if (data["Gender"] == "1"):
if (female_count != 0):
self.response.write(",")
self.response.write(data)
female_count = female_count + 1
self.response.write("]")
# You have post code now.
# TODO
#...
#Pretend that you have geo info back
#TODO send back JSON
# convert postcode to geographical information
# "GroupProjectID": "0001",
# "GroupProjectMemberID": "10001",
# "GROUPID": "200",
# "KeyFundStage": "1",
# "Gender": "Male",
# "Postcode": "SO17 2HQ"
# "lat": ""
# "long" ""
# Send response back to client
class Data:
datas = [{
"GroupProjectID": "0001",
"GroupProjectMemberID": "10001",
"GROUPID": "200",
"KeyFundStage": "1",
"Gender": "1",
"Postcode": "SO17 2HQ",
"lat" : "51.9241468414",
"long" : "-1939086340051"
}, {
"GroupProjectID": "0002",
"GroupProjectMemberID": "10001",
"GROUPID": "201",
"KeyFundStage": "3",
"Gender": "0",
"Postcode": "SO17 2LB",
"lat" : "50.9241468414",
"long" : "-1.39086340051"
}, {
"GroupProjectID": "0003",
"GroupProjectMemberID": "10001",
"GROUPID": "202",
"KeyFundStage": "4",
"Gender": "1",
"Postcode": "SO15 2DB",
"lat" : "49.9241468414",
"long" : "-0.39086340051"
}]
app = webapp2.WSGIApplication([('/', MainPage),
('/getData', GetData)],
debug=True)