-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-PA-churches.py
More file actions
64 lines (48 loc) · 1.61 KB
/
get-PA-churches.py
File metadata and controls
64 lines (48 loc) · 1.61 KB
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
import pprint
import requests
import urllib
import json
q = """PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbo: <http://dbpedia.org/ontology/>
select distinct ?church ?label ?lat ?long ?thumbnail
where
{
?church dct:subject dbc:Churches_in_Palermo .
?church rdfs:label ?label .
?church geo:lat ?lat .
?church geo:long ?long .
?church dbo:thumbnail ?thumbnail .
}
"""
params = {"query":q}
ash = urllib.urlencode(params)
DBpedia = "http://dbpedia.org/sparql?"+ash+"&format=json&run=+Run+Query+"
#DBlink = DBpedia['value']
r = requests.get(DBpedia)
results = json.loads(r.text)
churches = {}
for result in results["results"]["bindings"]:
if result['church'].has_key('value'):
resource = result['church']['value']
if result.has_key('label'):
name = result['label']['value']
lang = result['label']['xml:lang']
if churches.has_key(resource):
churches[resource]['name'][lang] = name
else:
churches[resource] = {}
churches[resource]['name'] = {}
churches[resource]['name'][lang] = name
lat = result['lat']['value']
churches[resource]['lat'] = lat
long = result['long']['value']
churches[resource]['long'] = long
if result.has_key('thumbnail'):
#church['img'] = result["thumbnail"]["value"]
img = result['thumbnail']['value']
churches[resource]['img'] = img
churches = json.dumps(churches)
#print(r.text)
print(churches)