Mercurial > hg > events2kml
diff eventsRestService.py @ 0:26c06d568e1d
first
author | dwinter |
---|---|
date | Thu, 13 Sep 2012 16:56:49 +0200 |
parents | |
children | 283badd62593 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eventsRestService.py Thu Sep 13 16:56:49 2012 +0200 @@ -0,0 +1,151 @@ +import web +import eventsDB2kml +import harvestDataFromEvents +import urllib +urls = ( + '/xpath/(.*)', 'xpath', + '/species', 'species', + '/applicants', 'applicants', + '/locations','locations' +) +app = web.application(urls, globals()) + +E4D_URL="http://localhost:8180/e4D/" +BASE_URL="http://localhost:8080/" +class locations: + + def GET(self): + + ret="" + + url1=urllib.quote_plus("http://localhost/outApplicants.xml") + ret+=""" + + <a href=" + %s?kml1=%s&source1=1" + target="e4D">applicants</a><br/> + """%(E4D_URL,url1) + + + url2=urllib.quote_plus("http://localhost/outResearch.xml") + ret+=""" + + <a href=" + %s?kml1=%s&source1=1" + target="e4D">research</a><br/> + """%(E4D_URL,url2) + + ret+= """ + <a href=" + %s?kml1=%s&source1=1&kml2=%s&source2=1" + target="e4D">both</a><br/> + """%(E4D_URL,url1,url2) + + return ret + + + +class xpath: + + def GET(self, path): + + if not path: + return "" + + x = web.input() + q= x.get("q") + + db = eventsDB2kml.DBQuery() + res= "<events>"+db.searchXPath(path, q)+"</events>" + + + + hv=harvestDataFromEvents.EventKMLTransformer() + + + #x,cnt=hv.readString(res, ".//research_location/place_information", 0) + x,cnt=hv.readString(res, ".//place_information", 0) + + + + s = hv.toKML(x) + + return s + +class applicants: + + def GET(self): + db = eventsDB2kml.DBQuery() + q=""" + select + cast(xpath('//applicant/name/text()', data) as text[]) AS name + from locations + """ + + res=db.query(q) + #hole alle species + spec=set() + + for r in res: + + l=r[0] + for x in l: + spec.add(x) + + ret="" + spList=[x for x in spec] + + spList.sort() + for x in spList: + print x + ret+="""<a href="/xpath///applicant/name/text()?q=%s">%s</a>"""%(x,x) + + url=urllib.quote_plus("%sxpath///applicant/name/text()?q=%s"%(BASE_URL,x)) + ret+=""" + + <a href=" + %s?kml1=%s&source1=1" + target="e4D">e4D</a><br/> + """%(E4D_URL,url) + + return ret +class species: + + def GET(self): + db = eventsDB2kml.DBQuery() + q=""" + select + cast(xpath('//species/text()', data) as text[]) AS name + from locations + """ + + res=db.query(q) + #hole alle species + spec=set() + + for r in res: + + l=r[0] + for x in l: + spec.add(x) + + ret="" + spList=[x for x in spec] + + spList.sort() + for x in spList: + print x + ret+="""<a href="/xpath///species/text()?q=%s">%s</a>"""%(x,x) + + url=urllib.quote_plus("%sxpath///species/text()?q=%s"%(BASE_URL,x)) + ret+=""" + + <a href=" + %s?kml1=%s&source1=1" + target="e4D">e4D</a><br/> + """%(E4D_URL,url) + + return ret + +if __name__ == "__main__": + app.run() \ No newline at end of file