Mercurial > hg > events2kml
comparison eventsRestService.py @ 0:26c06d568e1d
first
author | dwinter |
---|---|
date | Thu, 13 Sep 2012 16:56:49 +0200 |
parents | |
children | 283badd62593 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26c06d568e1d |
---|---|
1 import web | |
2 import eventsDB2kml | |
3 import harvestDataFromEvents | |
4 import urllib | |
5 urls = ( | |
6 '/xpath/(.*)', 'xpath', | |
7 '/species', 'species', | |
8 '/applicants', 'applicants', | |
9 '/locations','locations' | |
10 ) | |
11 app = web.application(urls, globals()) | |
12 | |
13 E4D_URL="http://localhost:8180/e4D/" | |
14 BASE_URL="http://localhost:8080/" | |
15 class locations: | |
16 | |
17 def GET(self): | |
18 | |
19 ret="" | |
20 | |
21 url1=urllib.quote_plus("http://localhost/outApplicants.xml") | |
22 ret+=""" | |
23 | |
24 <a href=" | |
25 %s?kml1=%s&source1=1" | |
26 target="e4D">applicants</a><br/> | |
27 """%(E4D_URL,url1) | |
28 | |
29 | |
30 url2=urllib.quote_plus("http://localhost/outResearch.xml") | |
31 ret+=""" | |
32 | |
33 <a href=" | |
34 %s?kml1=%s&source1=1" | |
35 target="e4D">research</a><br/> | |
36 """%(E4D_URL,url2) | |
37 | |
38 ret+= """ | |
39 <a href=" | |
40 %s?kml1=%s&source1=1&kml2=%s&source2=1" | |
41 target="e4D">both</a><br/> | |
42 """%(E4D_URL,url1,url2) | |
43 | |
44 return ret | |
45 | |
46 | |
47 | |
48 class xpath: | |
49 | |
50 def GET(self, path): | |
51 | |
52 if not path: | |
53 return "" | |
54 | |
55 x = web.input() | |
56 q= x.get("q") | |
57 | |
58 db = eventsDB2kml.DBQuery() | |
59 res= "<events>"+db.searchXPath(path, q)+"</events>" | |
60 | |
61 | |
62 | |
63 hv=harvestDataFromEvents.EventKMLTransformer() | |
64 | |
65 | |
66 #x,cnt=hv.readString(res, ".//research_location/place_information", 0) | |
67 x,cnt=hv.readString(res, ".//place_information", 0) | |
68 | |
69 | |
70 | |
71 s = hv.toKML(x) | |
72 | |
73 return s | |
74 | |
75 class applicants: | |
76 | |
77 def GET(self): | |
78 db = eventsDB2kml.DBQuery() | |
79 q=""" | |
80 select | |
81 cast(xpath('//applicant/name/text()', data) as text[]) AS name | |
82 from locations | |
83 """ | |
84 | |
85 res=db.query(q) | |
86 #hole alle species | |
87 spec=set() | |
88 | |
89 for r in res: | |
90 | |
91 l=r[0] | |
92 for x in l: | |
93 spec.add(x) | |
94 | |
95 ret="" | |
96 spList=[x for x in spec] | |
97 | |
98 spList.sort() | |
99 for x in spList: | |
100 print x | |
101 ret+="""<a href="/xpath///applicant/name/text()?q=%s">%s</a>"""%(x,x) | |
102 | |
103 url=urllib.quote_plus("%sxpath///applicant/name/text()?q=%s"%(BASE_URL,x)) | |
104 ret+=""" | |
105 | |
106 <a href=" | |
107 %s?kml1=%s&source1=1" | |
108 target="e4D">e4D</a><br/> | |
109 """%(E4D_URL,url) | |
110 | |
111 return ret | |
112 class species: | |
113 | |
114 def GET(self): | |
115 db = eventsDB2kml.DBQuery() | |
116 q=""" | |
117 select | |
118 cast(xpath('//species/text()', data) as text[]) AS name | |
119 from locations | |
120 """ | |
121 | |
122 res=db.query(q) | |
123 #hole alle species | |
124 spec=set() | |
125 | |
126 for r in res: | |
127 | |
128 l=r[0] | |
129 for x in l: | |
130 spec.add(x) | |
131 | |
132 ret="" | |
133 spList=[x for x in spec] | |
134 | |
135 spList.sort() | |
136 for x in spList: | |
137 print x | |
138 ret+="""<a href="/xpath///species/text()?q=%s">%s</a>"""%(x,x) | |
139 | |
140 url=urllib.quote_plus("%sxpath///species/text()?q=%s"%(BASE_URL,x)) | |
141 ret+=""" | |
142 | |
143 <a href=" | |
144 %s?kml1=%s&source1=1" | |
145 target="e4D">e4D</a><br/> | |
146 """%(E4D_URL,url) | |
147 | |
148 return ret | |
149 | |
150 if __name__ == "__main__": | |
151 app.run() |