0
|
1 #diese klasse fragt die postgres db ab und erzeugt ein kml file aus den abfragen
|
|
2
|
|
3 import psycopg2
|
|
4 import harvestDataFromEvents
|
|
5
|
|
6 class DBQuery:
|
|
7 def __init__(self):
|
|
8 self.conn=psycopg2.connect("dbname='mmpermits' user='postgres' host='localhost' password='XX'")
|
|
9 self.cur=self.conn.cursor()
|
|
10
|
|
11
|
|
12
|
|
13 def searchXPath(self,xpath,searchTerm):
|
|
14 query="""select data from locations
|
|
15 where
|
|
16 '%s' = ANY (cast (xpath('%s', data) as text[])) ;
|
|
17 """%(searchTerm,xpath)
|
|
18
|
|
19
|
|
20 self.cur.execute(query)
|
|
21
|
|
22
|
|
23 results= self.cur.fetchall()
|
|
24
|
|
25 ret=""
|
|
26 for result in results:
|
|
27 ret+=result[0]+"\n"
|
|
28
|
|
29
|
|
30
|
|
31 return ret
|
|
32
|
|
33 def query(self,q):
|
|
34 self.cur.execute(q)
|
|
35 results= self.cur.fetchall()
|
|
36
|
|
37 return results
|
|
38
|
|
39
|
|
40 if __name__ == '__main__':
|
|
41 db = DBQuery()
|
|
42 res= "<events>"+db.searchXPath("//name/text()", "Brian L. Cypher")+"</events>"
|
|
43
|
|
44
|
|
45
|
|
46 hv=harvestDataFromEvents.EventKMLTransformer()
|
|
47
|
|
48
|
|
49 x,cnt=hv.readString(res, ".//research_location/place_information", 0)
|
|
50
|
|
51 hv.close()
|
|
52
|
|
53 s = hv.toKML(x)
|
|
54
|
|
55 print s
|
|
56
|