0
|
1 import web
|
|
2 import eventsDB2kml
|
|
3 import harvestDataFromEvents
|
|
4 import urllib
|
1
|
5 import urlparse
|
|
6
|
0
|
7 urls = (
|
|
8 '/xpath/(.*)', 'xpath',
|
1
|
9 '/xpathSearch', 'xpathSearch',
|
|
10 '/sqlSearch', 'sqlSearch',
|
|
11 '/sql', 'sql',
|
0
|
12 '/species', 'species',
|
|
13 '/applicants', 'applicants',
|
1
|
14 '/locations','locations',
|
|
15 '/restricted', 'restricted'
|
0
|
16 )
|
|
17 app = web.application(urls, globals())
|
|
18
|
3
|
19 #E4D_URL="http://localhost/mmpa/"
|
|
20 E4D_URL="http://localhost/~dwinter/mmpa/events2kml/mmpa/"
|
1
|
21 BASE_URL="http://localhost/m/"
|
|
22
|
|
23 APPLICANT_FILE_NAME="http://localhost/outApplicants.xml"
|
|
24 RESEARCH_FILE_NAME="http://localhost/outResearch.xml"
|
0
|
25 class locations:
|
|
26
|
|
27 def GET(self):
|
|
28
|
|
29 ret=""
|
|
30
|
1
|
31 url1=urllib.quote_plus(APPLICANT_FILE_NAME)
|
0
|
32 ret+="""
|
|
33
|
4
|
34 <a href="javascript:callKML('%s','applicants')">applicants</a><br/>
|
|
35
|
|
36 """%(url1)
|
|
37
|
0
|
38
|
|
39
|
1
|
40 url2=urllib.quote_plus(RESEARCH_FILE_NAME)
|
0
|
41 ret+="""
|
|
42
|
4
|
43 <a href="javascript:callKML('%s','research')">research</a><br/>
|
|
44 """%(url2)
|
|
45
|
0
|
46
|
|
47 ret+= """
|
4
|
48 <a href="javascript:callKMLs('%s','%s')">both</a><br/>
|
|
49 """%(url1,url2)
|
|
50
|
0
|
51
|
|
52 return ret
|
|
53
|
1
|
54 class restricted:
|
|
55 def GET(self):
|
|
56 x=web.input()
|
|
57 pathes=x.get("path")
|
|
58 print pathes
|
|
59 select=x.get("select")
|
|
60 newRestriction=x.get("newRestriction")
|
|
61
|
|
62 if select is None:
|
|
63 select="data"
|
|
64
|
|
65
|
|
66
|
|
67 #path kann meherer abfragen enthalten durch | getrennt
|
|
68
|
|
69 splittedPath = pathes.split("|")
|
|
70 print splittedPath
|
|
71 queriesArray=[]
|
|
72 for xlinkPath in splittedPath:
|
|
73 url = urllib.unquote_plus(xlinkPath);
|
0
|
74
|
|
75
|
1
|
76 qs=urlparse.urlparse(url).query
|
|
77
|
|
78 queries=urlparse.parse_qsl(qs)
|
|
79 q=""
|
|
80 for query in queries:
|
|
81 if query[0]=='q':
|
|
82 q=query[1]
|
|
83
|
|
84
|
|
85
|
|
86
|
|
87
|
|
88 url= urlparse.urlparse(url).path
|
|
89
|
|
90 pathSplitted=url.split("xpath/")
|
|
91 if len(pathSplitted)>1:
|
|
92 path=pathSplitted[1]
|
|
93 queriesArray.append((path,q))
|
|
94 print queriesArray
|
|
95
|
|
96
|
|
97
|
|
98 db = eventsDB2kml.DBQuery()
|
|
99
|
|
100 if newRestriction is None: # keine weiteren Einschaenkungen dann erzeugen das kml file
|
|
101 res= "<events>"+ db.searchXPaths(queriesArray)+"</events>"
|
|
102
|
|
103
|
|
104
|
|
105 hv=harvestDataFromEvents.EventKMLTransformer()
|
|
106
|
|
107
|
|
108 #x,cnt=hv.readString(res, ".//research_location/place_information", 0)
|
|
109 x,cnt=hv.readString(res, ".//place_information", 0)
|
|
110
|
|
111
|
|
112
|
|
113 s = hv.toKML(x)
|
|
114
|
|
115 return s
|
|
116
|
|
117
|
|
118 #sonst suche nach restriction suche muss eine liste von werten ergeben die sich mit der REstriction versteht, dh. restriction =wert wird dann in die Links eingebaut
|
|
119 # e.g. man such nach name d.h
|
|
120 # select=%20distinct%20cast%28xpath%28%27//applicant/name/text%28%29%27,%20data%29%20as%20text[]%29%20AS%20name
|
|
121 # dann muss die Restriction darauf passen i.a. wird die Restriction dem xpath im Suchstring entsprechen,
|
|
122 # newRestriction=http%3A%2F%2Flocalhost%2Fm%2Fxpath%2F%2F%2Fapplicant%2Fnam%2Ftext%28%29%
|
|
123
|
|
124 newRestriction=urllib.unquote_plus(newRestriction)
|
|
125
|
|
126 vals = db.searchXPaths(queriesArray,select,True)
|
|
127
|
|
128
|
|
129 ret=""
|
|
130
|
|
131
|
|
132 #berechen den neuer link = alter path ergaenzt um neue restriction
|
|
133 for val in vals:
|
|
134 val=val[0] # result ist immer ein tuple
|
|
135 # mehr als ein Treffer pro eintrag
|
|
136 for v in val:
|
|
137 newQuery=""
|
|
138 splittedPath.append(newRestriction+"?q="+v)
|
|
139 splittedPathQuoted=[urllib.quote_plus(x) for x in splittedPath]
|
|
140
|
|
141 pathNew="|".join(splittedPathQuoted)
|
|
142 urlNew=urllib.quote_plus("""%srestricted?path=%s"""%(BASE_URL,pathNew))
|
|
143 ret+="""<a href="%s?kml1=%s&source1=1">%s</a><br/>"""%(E4D_URL,urlNew,v)
|
|
144 return ret
|
|
145
|
|
146 class sqlSearch:
|
|
147 def GET(self):
|
|
148 x=web.input()
|
|
149 sql=x.get("sql")
|
|
150 p=x.get("xpathPlace")
|
|
151 output=x.get("output")
|
|
152
|
|
153
|
|
154
|
|
155 url="%ssql?q=%s&p=%s"%(BASE_URL,urllib.quote_plus(sql),p)
|
|
156
|
|
157 if output=="sql":
|
|
158 raise web.seeother(url)
|
|
159
|
|
160 url=urllib.quote_plus(url)
|
|
161
|
|
162
|
|
163
|
|
164 url="""%s?kml1=%s&source1=1"""%(E4D_URL,url)
|
|
165 raise web.seeother(url)
|
|
166
|
|
167
|
|
168 class xpathSearch:
|
|
169 def GET(self):
|
|
170 x=web.input()
|
|
171 path=x.get("path")
|
|
172 value=x.get("value")
|
|
173
|
|
174 url="%sxpath/%s?q=%s"%(BASE_URL,path,value)
|
|
175
|
|
176 url=urllib.quote_plus(url)
|
|
177
|
|
178
|
|
179
|
|
180 url="""%s?kml1=%s&source1=1"""%(E4D_URL,url)
|
|
181 raise web.seeother(url)
|
|
182
|
|
183 class sql:
|
|
184 def GET(self):
|
|
185 x = web.input()
|
|
186 q= x.get("q")
|
|
187 p= x.get("p")
|
|
188 db = eventsDB2kml.DBQuery()
|
|
189 res= "<events>"+db.sql(q)+"</events>"
|
|
190
|
|
191
|
|
192
|
|
193 hv=harvestDataFromEvents.EventKMLTransformer()
|
|
194
|
|
195
|
|
196 #x,cnt=hv.readString(res, ".//research_location/place_information", 0)
|
|
197 x,cnt=hv.readString(res, p, 0)
|
|
198
|
|
199
|
|
200
|
|
201 s = hv.toKML(x)
|
|
202
|
|
203 return s
|
|
204
|
|
205
|
0
|
206 class xpath:
|
|
207
|
|
208 def GET(self, path):
|
|
209
|
|
210 if not path:
|
|
211 return ""
|
|
212
|
|
213 x = web.input()
|
|
214 q= x.get("q")
|
|
215
|
|
216 db = eventsDB2kml.DBQuery()
|
|
217 res= "<events>"+db.searchXPath(path, q)+"</events>"
|
|
218
|
|
219
|
|
220
|
|
221 hv=harvestDataFromEvents.EventKMLTransformer()
|
|
222
|
|
223
|
|
224 #x,cnt=hv.readString(res, ".//research_location/place_information", 0)
|
|
225 x,cnt=hv.readString(res, ".//place_information", 0)
|
|
226
|
|
227
|
|
228
|
|
229 s = hv.toKML(x)
|
|
230
|
|
231 return s
|
|
232
|
|
233 class applicants:
|
|
234
|
|
235 def GET(self):
|
|
236 db = eventsDB2kml.DBQuery()
|
1
|
237
|
|
238
|
|
239 x = web.input()
|
|
240 where= x.get("where")
|
|
241
|
|
242 whereClause=""
|
|
243
|
|
244 #Beispiel:
|
|
245 #select distinct
|
|
246 #
|
|
247 #cast (xpath('//name/text()',data) as text[]) AS name
|
|
248 #
|
|
249 #from locations
|
|
250 # where
|
|
251 # 'Astrophytum asterius' = ANY (cast (xpath('//species/text()', data) as text[])) ;
|
|
252
|
|
253 if where!="" and where is not None:
|
|
254 whereClause="where %s"%where
|
|
255
|
0
|
256 q="""
|
|
257 select
|
|
258 cast(xpath('//applicant/name/text()', data) as text[]) AS name
|
|
259 from locations
|
1
|
260 %s
|
|
261 """%whereClause
|
0
|
262
|
|
263 res=db.query(q)
|
|
264 #hole alle species
|
|
265 spec=set()
|
|
266
|
|
267 for r in res:
|
|
268
|
|
269 l=r[0]
|
|
270 for x in l:
|
|
271 spec.add(x)
|
|
272
|
|
273 ret=""
|
|
274 spList=[x for x in spec]
|
|
275
|
|
276 spList.sort()
|
|
277 for x in spList:
|
1
|
278
|
|
279 ret+="""<a href="%sxpath///applicant/name/text()?q=%s">%s</a>"""%(BASE_URL,x,x)
|
0
|
280
|
|
281 url=urllib.quote_plus("%sxpath///applicant/name/text()?q=%s"%(BASE_URL,x))
|
|
282 ret+="""
|
|
283
|
4
|
284 <a href="javascript:callKML('%s','%s')">e4D</a><br/>
|
|
285 """%(url,x)
|
|
286
|
0
|
287
|
|
288 return ret
|
|
289 class species:
|
|
290
|
|
291 def GET(self):
|
|
292 db = eventsDB2kml.DBQuery()
|
1
|
293
|
|
294 x = web.input()
|
|
295 where= x.get("where")
|
|
296
|
|
297 whereClause=""
|
|
298
|
|
299 # Beispiel:
|
|
300 #select
|
|
301 #
|
|
302 #cast (xpath('//species/text()',data) as text[]) AS name
|
|
303 #
|
|
304 #from locations
|
|
305 # where
|
|
306 # 'Anna George' = ANY (cast (xpath('//name/text()', data) as text[])) ;
|
|
307 #
|
|
308 if where!="" and where is not None:
|
|
309 whereClause="where %s"%where
|
|
310
|
0
|
311 q="""
|
1
|
312 select distinct
|
0
|
313 cast(xpath('//species/text()', data) as text[]) AS name
|
|
314 from locations
|
1
|
315 %s
|
|
316 """%whereClause
|
|
317
|
|
318
|
0
|
319 res=db.query(q)
|
|
320 #hole alle species
|
|
321 spec=set()
|
|
322
|
|
323 for r in res:
|
|
324
|
|
325 l=r[0]
|
|
326 for x in l:
|
|
327 spec.add(x)
|
|
328
|
|
329 ret=""
|
|
330 spList=[x for x in spec]
|
|
331
|
|
332 spList.sort()
|
|
333 for x in spList:
|
1
|
334
|
|
335 ret+="""<a href="%sxpath///species/text()?q=%s">%s</a>"""%(BASE_URL,x,x)
|
0
|
336
|
|
337 url=urllib.quote_plus("%sxpath///species/text()?q=%s"%(BASE_URL,x))
|
|
338 ret+="""
|
|
339
|
4
|
340 <a href="javascript:callKML('%s','%s')">e4D</a><br/>
|
|
341 """%(url,x)
|
0
|
342
|
|
343 return ret
|
|
344
|
|
345 if __name__ == "__main__":
|
|
346 app.run() |