# generate a list of wikidata entities related to keywords
from os import path
from sys import stdout
-from wikidata_api_calls import search_wikidata
+from wikidata_api_calls import search_wikidata, get_wikidata_api
class Wikidata_ResultSet(object):
def __init__(self):
def to_csv(self, outfile=None):
- header = ','.join(['search_term', 'entityid', 'pageid', 'search_position','timestamp'])
+ header = ','.join(['search_term', 'entityid', 'pageid', 'search_position','timestamp']) + '\n'
if outfile is None:
of = stdout
# File defines functions for making api calls to find translations and transliterations for key terms.
import mwapi
+import requests
import sys
-sys.path.append("..")
from defaults import user_agent
def get_wikidata_api():
raise mwapi.session.APIError(f"No results for query: {term}")
return results
+
+def run_sparql_query(q):
+ results = requests.get("https://query.wikidata.org/bigdata/namespace/wdq/sparql?query={q}&format=json")
+