Skip to content

Commit

Permalink
handle api citation-count err – count 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanhb committed Sep 3, 2024
1 parent eb99c78 commit a358b94
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions indexapi_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,18 @@ def ___contains_days(date):

return result

def __get_ids_from_meta(values):
def __get_ids_from_meta(values, final_res = dict()):
MAX_VALUES = 3000

values_part = values[:MAX_VALUES]
values_rest = values[MAX_VALUES:]

sparql_endpoint = "https://test.opencitations.net/meta/sparql"
sparql_query = """
PREFIX datacite: <http://purl.org/spar/datacite/>
PREFIX literal: <http://www.essepuntato.it/2010/06/literalreification/>
SELECT ?br_omid ?identifier_val ?scheme {
VALUES ?br_omid { """+" ".join(values)+""" }
VALUES ?br_omid { """+" ".join(values_part)+""" }
?br_omid datacite:hasIdentifier ?identifier .
?identifier literal:hasLiteralValue ?identifier_val .
?identifier datacite:usesIdentifierScheme ?scheme .
Expand All @@ -413,9 +418,9 @@ def __get_ids_from_meta(values):
headers={"Accept": "application/sparql-results+json", "Content-Type": "application/sparql-query"}
data = {"query": sparql_query}

res = defaultdict(set)
try:
response = post(sparql_endpoint, headers=headers, data=sparql_query)
res = defaultdict(set)
if response.status_code == 200:
r = loads(response.text)
results = r["results"]["bindings"]
Expand All @@ -426,10 +431,16 @@ def __get_ids_from_meta(values):
anyid_pref = elem["scheme"]["value"].split("datacite/")[1]
anyid_val = elem["identifier_val"]["value"]
res[omid_br].add(anyid_pref+":"+anyid_val)
return res.values()
return []
except:
return []
pass

for k in res:
final_res[k] = res[k]
if len(values_rest) > 0:
return __get_ids_from_meta(values_rest, final_res)
else:
return final_res.values()


def __br_meta_metadata(values):
sparql_endpoint = "http://127.0.0.1/meta/sparql"
Expand Down

0 comments on commit a358b94

Please sign in to comment.