Skip to content

Commit 3abef26

Browse files
committed
a bit nicer example
1 parent 2952cd7 commit 3abef26

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/sparql_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424

2525
class OAuthSparqlTest(object):
26+
"""Wraps OAuth1 with SPARQL-client to provide nice API"""
2627
def __init__(self, sparql_endpoint, consumer_token, consumer_secret, access_token, access_secret):
2728
self.endpoint = sparql_endpoint
2829

@@ -38,9 +39,10 @@ def query(self, sparql_query, graph):
3839
return requests.get('%s?%s' % (self.endpoint, qs), headers={"Accept": "application/sparql-results+json"}, auth=self.oauth)
3940

4041

41-
sparqler = OAuthSparqlTest('https://api.grids.by/v1/sparql', consumer_token, consumer_secret, access_token, access_secret)
42-
result = sparqler.query('SELECT * WHERE {?s ?p ?o}', graph_iri)
42+
if __name__ == '__main__':
43+
sparqler = OAuthSparqlTest('https://api.grids.by/v1/sparql', consumer_token, consumer_secret, access_token, access_secret)
44+
result = sparqler.query('SELECT COUNT(*) as ?count WHERE {?s ?p ?o}', graph_iri)
4345

44-
data = json.loads(result.content)
46+
data = json.loads(result.content)
4547

46-
print(json.dumps(data, indent=4, separators=(',', ': ')))
48+
print(json.dumps(data, indent=4, separators=(',', ': ')))

0 commit comments

Comments
 (0)