-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·99 lines (83 loc) · 2.46 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
#!/usr/bin/env python
import wsgiref.handlers
import os
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template
#custom imports
import models
import geocode
import geo.geotypes
class MainHandler(webapp.RequestHandler):
def get(self):
self.redirect('/loc/place/98004/')
#template_values = {
#"nadda" : "temps"
#}
#path = os.path.join(os.path.dirname(__file__), 'templates/main.html')
#self.response.out.write(template.render(path, template_values))
class Loc(webapp.RequestHandler):
def get(self):
self.request.path_info_pop()
loctype = self.request.path_info_pop()
if loctype == "place":
locstring = self.request.path_info_pop()
gc = geocode.GeoCode()
locdata = gc.getCoords(locstring)
try:
coords = locdata["Placemark"][0]["Point"]["coordinates"]
except:
#47.6264794,-122.2051487
coords = (-122.2051487, 47.6264794)
elif loctype == "coords":
lat = self.request.path_info_pop()
lon = self.request.path_info_pop()
coords = (float(lat), float(lon))
else:
self.response.out.write("""<h1>Bad loctype</h1>
<p>Options are /place/ or /coords/</p>
""")
return
template_values = {
"center_lat" : coords[0],
"center_lon" : coords[1]
}
path = os.path.join(os.path.dirname(__file__), 'templates/loc.html')
self.response.out.write(template.render(path, template_values))
class Test(webapp.RequestHandler):
def get(self):
self.response.out.write(self.request)
class Latest(webapp.RequestHandler):
def get(self):
q = models.Post.gql("ORDER BY modified DESC")
results = q.fetch(10)
ph = []
for p in results:
pt = {}
pt['id'] = str(p.key().id())
pt['picid'] = str(p.pic.key().id())
pt['content'] = p.content
ph.append(pt)
template_values = {
"posts" : ph
}
path = os.path.join(os.path.dirname(__file__), 'templates/rpc_table.html')
self.response.out.write(template.render(path, template_values))
class Updater(webapp.RequestHandler):
def get(self):
#posts = models.Post.all()
#for p in posts:
# p.put()
self.response.out.write("no more updating")
def main():
application = webapp.WSGIApplication([
('/', MainHandler),
('/loc.*', Loc),
('/test/.*', Test),
('/latest.*', Latest),
('/updateModels.*', Updater)
],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()