diff --git a/src/zbmath_rest2oai/getAsXml.py b/src/zbmath_rest2oai/getAsXml.py index 21148790..b1f29765 100644 --- a/src/zbmath_rest2oai/getAsXml.py +++ b/src/zbmath_rest2oai/getAsXml.py @@ -41,13 +41,13 @@ class EntryNotFoundException(Exception): pass -def apply_zbmath_api_fixes(result, prefix): +def apply_zbmath_api_fixes(result, prefix_get_as_xml): if result.get('datestamp'): result['datestamp'] = (result['datestamp']. replace('0001-01-01T00:00:00Z', '0001-01-01T00:00:00')) if result.get('id'): - result['id'] = prefix + str(result['id']) + result['id'] = prefix_get_as_xml + str(result['id']) old_states = result.get('states') if old_states is None: return @@ -77,6 +77,7 @@ def extract_tags(result): def add_references_to_software(api_uri, dict_res): list_articles_ids_to_soft = [] list_articles_ids_and_alter_ids_to_soft = [] + list_references_year_alt = [] if "software" in api_uri: if api_uri.startswith("https://api.zbmath.org/v1/software/_all?start_after=")==False: soft_id=api_uri.split("/")[-1] @@ -101,6 +102,10 @@ def api_doc_endpoint(page): list_ids_and_alter.append(";".join([str(entry["id"])]+list_links)) + if "datestamp" in entry: + year = entry["datestamp"][:4] + list_references_year_alt.append(year) + list_articles_ids_to_soft.extend(list_ids) list_articles_ids_and_alter_ids_to_soft.extend(list_ids_and_alter) @@ -110,10 +115,11 @@ def api_doc_endpoint(page): dict_res["references"] = list_articles_ids_to_soft # Wrap it in a list to make it iterable for your existing loop dict_res["references_alt"] = list_articles_ids_and_alter_ids_to_soft + dict_res["references_year_alt"] = list_references_year_alt dict_res = [dict_res] return dict_res -def final_xml2(api_source, prefix): +def final_xml2(api_source, prefix_final_xml2): headers = {'Accept': 'application/json'} r = requests.get(api_source, headers=headers, timeout=(10, 60)) if r.status_code == 404: @@ -135,14 +141,14 @@ def final_xml2(api_source, prefix): for result in json["result"]: if isinstance(result, list): result = result[0] - apply_zbmath_api_fixes(result, prefix) + apply_zbmath_api_fixes(result, prefix_final_xml2) identifier = result["id"] dict_math_entities[identifier] = _illegal_xml_chars_RE.sub("", Converter(wrap="root").build( result, closed_tags_for=[[], '', [None], None])) tags[identifier] = extract_tags(result) elif isinstance(result, dict): - apply_zbmath_api_fixes(result, prefix) + apply_zbmath_api_fixes(result, prefix_final_xml2) identifier = result["id"] dict_math_entities[identifier] = _illegal_xml_chars_RE.sub("", Converter(wrap="root").build( result, @@ -153,7 +159,7 @@ def final_xml2(api_source, prefix): if __name__ == "__main__": if "document" in sys.argv[1]: - prefix="oai:zbmath.org:" + prefix_final_xml2_main = "oai:zbmath.org:" else: - prefix="oai:swmath.org:" - print(final_xml2(sys.argv[1], prefix)) + prefix_final_xml2_main = "oai:swmath.org:" + print(final_xml2(sys.argv[1], prefix_final_xml2_main)) diff --git a/test/data/software/plain_with_references.xml b/test/data/software/plain_with_references.xml index df1ff406..0964d626 100644 --- a/test/data/software/plain_with_references.xml +++ b/test/data/software/plain_with_references.xml @@ -250,6 +250,117 @@ 6666873;10.1016/j.jcp.2016.06.039 5538352;10.1007/978-3-540-71992-2_17 2234457 + 2005 + 2012 + 2009 + 2007 + 2023 + 2018 + 2007 + 2024 + 2008 + 2008 + 2005 + 2015 + 2015 + 2021 + 2008 + 2011 + 2010 + 2011 + 2007 + 2007 + 2008 + 2008 + 2017 + 2010 + 2019 + 2010 + 2019 + 2023 + 2007 + 2016 + 2011 + 2010 + 2013 + 2016 + 2017 + 2024 + 2019 + 2019 + 2023 + 2011 + 2008 + 2016 + 2023 + 2011 + 2010 + 2009 + 2019 + 2016 + 2015 + 2019 + 2018 + 2014 + 2019 + 2015 + 2018 + 2015 + 2014 + 2013 + 2007 + 2012 + 2021 + 2021 + 2020 + 2010 + 2022 + 2008 + 2007 + 2018 + 2014 + 2009 + 2007 + 2023 + 2011 + 2018 + 2011 + 2010 + 2024 + 2022 + 2010 + 2010 + 2021 + 2010 + 2022 + 2022 + 2022 + 2023 + 2011 + 2021 + 2021 + 2024 + 2014 + 2024 + 2022 + 2010 + 2020 + 2023 + 2016 + 2011 + 2020 + 2020 + 2019 + 2020 + 2024 + 2018 + 2021 + 2016 + 2024 + 2018 + 2016 + 2009 + 2005 4013 MUMPS