From cd27cb0ec36376e6f860301d8ab87fd5141b1d0f Mon Sep 17 00:00:00 2001 From: Julian <1261560+jschibberges@users.noreply.github.com> Date: Thu, 30 May 2024 22:41:02 +0200 Subject: [PATCH 1/2] Adding function to filter recently added documents --- bundestag_api/bta_wrapper.py | 73 ++++++------------------------------ bundestag_api/models.py | 8 ---- requirements.txt | 6 +-- setup.py | 2 +- 4 files changed, 15 insertions(+), 74 deletions(-) diff --git a/bundestag_api/bta_wrapper.py b/bundestag_api/bta_wrapper.py index 0fea593..7bb890a 100644 --- a/bundestag_api/bta_wrapper.py +++ b/bundestag_api/bta_wrapper.py @@ -44,7 +44,7 @@ class btaConnection: Retrieves plenary protocols specified by IDs """ - def __init__(self, apikey=None, debug=False): + def __init__(self, apikey=None): GEN_APIKEY = "rgsaY4U.oZRQKUHdJhF9qguHMkwCGIoLaqEcaHjYLF" DATE_GEN_APIKEY = "31.05.2024" @@ -287,7 +287,7 @@ def query(self, if r.status_code == requests.codes.ok: content = r.json() if content["numFound"] == 0: - # print("No data was returned.") + logging.info("No data was returned.") data = "No data was returned." prs = False elif content["numFound"] > 0 and content["numFound"] <= 50: @@ -406,7 +406,9 @@ def search_procedure(self, updated_since=updated_since, updated_until=updated_until, descriptor=descriptor, - sachgebiet=sachgebiet,) + sachgebiet=sachgebiet, + document_type=document_type, + title=title) return data def get_procedure(self, @@ -503,7 +505,9 @@ def search_procedureposition(self, date_end=date_end, num=num, updated_since=updated_since, - updated_until=updated_until,) + updated_until=updated_until,, + document_type=document_type, + title=title) return data def get_procedureposition(self, @@ -617,7 +621,9 @@ def search_document(self, institution=institution, num=num, updated_since=updated_since, - updated_until=updated_until,) + updated_until=updated_until, + document_type=document_type, + title=title) return data def get_document(self, @@ -924,61 +930,4 @@ def list_methods(self): """ list_of_methods = dir(btaConnection) list_of_methods = [item for item in list_of_methods if "__" not in item] - """ - list_of_methods = ["get_activity","search_activity","get_person", - "search_person", "get_plenaryprotocol", - "search_plenaryprotocol", "get_document", - "search_document", "get_procedureposition", - "search_procedureposition", "get_procedure", - "search_procedure", "query"] - """ return list_of_methods - - -def main_function(): - arguments = parse_args_to_dict(sys.argv[1:]) - if arguments.get("o") is not None: - output_format = arguments.get("o") - output_defined = True - arguments.pop("o") - if arguments.get("n") is not None: - file_name = arguments.get("n") - if output_format not in file_name: - file_name = file_name+"."+output_format - arguments.pop("n") - else: - raise ValueError("Output defined but no filename given.") - if arguments.get("apikey") is not None: - bta = btaConnection(apikey=arguments.get("apikey")) - arguments.pop("apikey") - else: - bta = btaConnection() - if arguments.get("method") is not None: - if arguments.get("method") in bta.list_methods(): - method = arguments.get("method") - arguments.pop("method") - if method == "searchProcedure": - data = bta.search_procedure(arguments) - else: - raise ValueError("No valid method supplied.") - else: - raise ValueError("No method supplied") - if output_defined == True: - if output_format == "xlsx" or output_format == "xls": - import pandas as pd - data = pd.json_normalize(data) - data.to_excel(file_name, index=False) - elif output_format == "csv": - import pandas as pd - data = pd.json_normalize(data) - data.to_csv(file_name, index=False) - elif output_format == "json": - import json - with open(file_name, 'w', encoding='utf-8') as f: - json.dump(data, f, ensure_ascii=False, indent=4) - else: - return data - - -if __name__ == "__main__": - main_function() diff --git a/bundestag_api/models.py b/bundestag_api/models.py index c1ec255..15b90f5 100644 --- a/bundestag_api/models.py +++ b/bundestag_api/models.py @@ -1,12 +1,4 @@ # -*- coding: utf-8 -*- -""" -Created on Fri Mar 1 22:45:35 2024 - -@author: jschi -""" - -# Classes - class Person: """This class represents a German parliamentarian""" diff --git a/requirements.txt b/requirements.txt index 69d77bb..6e51e04 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -openpyxl==3.0.7 -pandas==1.2.5 -requests==2.25.1 \ No newline at end of file +openpyxl>3.0.0 +pandas>1.2.0 +requests>2.0.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 1ed3370..1bccaf6 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ readme="README.md", license="MIT", name='bundestag_api', - version='1.0.3', + version='1.0.4', packages=find_packages(), install_requires=[ 'requests>=2.0.0', From 46f29152309356e853331bfd1c7202b1ea34db3f Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 30 May 2024 22:45:50 +0200 Subject: [PATCH 2/2] Update setup.py Update version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1bccaf6..6bcd211 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ readme="README.md", license="MIT", name='bundestag_api', - version='1.0.4', + version='1.0.5', packages=find_packages(), install_requires=[ 'requests>=2.0.0',