Skip to content

Commit

Permalink
Merge pull request #11 from jschibberges/dev
Browse files Browse the repository at this point in the history
Version 1.0.5
  • Loading branch information
jschibberges authored May 30, 2024
2 parents c79fe0b + 46f2915 commit 6cebc62
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 71 deletions.
71 changes: 10 additions & 61 deletions bundestag_api/bta_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,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:
Expand Down Expand Up @@ -407,7 +407,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,
Expand Down Expand Up @@ -504,7 +506,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,
Expand Down Expand Up @@ -618,7 +622,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,
Expand Down Expand Up @@ -925,61 +931,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()
8 changes: 0 additions & 8 deletions bundestag_api/models.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
requests>2.0.0
openpyxl>3.0.0
pandas>1.2.0
requests>2.0.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6cebc62

Please sign in to comment.