diff --git a/src/__init__.py b/src/__init__.py index babe404..706104c 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -47,18 +47,6 @@ class ItemSubjector(BaseModel): - @staticmethod - def login(): - with console.status("Logging in with WikibaseIntegrator..."): - config.login_instance = wbi_login.Login( - auth_method="login", - user=config.username, - password=config.password, - debug=False, - ) - # Set User-Agent - wbi_config.config["USER_AGENT_DEFAULT"] = config.user_agent - @staticmethod def match_main_subjects_from_sparql(args: argparse.Namespace = None): """Collect subjects via SPARQL and call get_validated_main_subjects() @@ -79,7 +67,6 @@ def match_main_subjects_from_sparql(args: argparse.Namespace = None): main_subjects = [] results = execute_sparql_query( args.sparql.replace("{", "{{").replace("}", "}}"), - debug=args.debug_sparql, ) for item_json in results["results"]["bindings"]: logging.debug(f"item_json:{item_json}") diff --git a/src/models/batch_jobs.py b/src/models/batch_jobs.py index 11c08a3..fef44e9 100644 --- a/src/models/batch_jobs.py +++ b/src/models/batch_jobs.py @@ -3,7 +3,9 @@ from pydantic import BaseModel +import config from src.models.batch_job import BatchJob +from src.models.login import Login class BatchJobs(BaseModel): @@ -35,9 +37,8 @@ def run_jobs(self): if self.jobs is None or len(self.jobs) == 0: raise ValueError("did not get what we need") print_keep_an_eye_on_wdqs_lag() - from src import login - - login() + if config.login_instance is None: + Login() self.print_running_jobs() start_time = datetime.now() for job in self.jobs: diff --git a/src/models/items/academic_journals.py b/src/models/items/academic_journals.py index 78a667a..b0e9c88 100644 --- a/src/models/items/academic_journals.py +++ b/src/models/items/academic_journals.py @@ -63,7 +63,6 @@ def process_results(results): SERVICE wikibase:label {{ bd:serviceParam wikibase:language "en". }} }} """, - debug=suggestion.args.debug_sparql, ) logging.info( f'Got {len(results["results"]["bindings"])} academic journal items from ' diff --git a/src/models/items/riksdagen_documents.py b/src/models/items/riksdagen_documents.py index d45892f..c74ff70 100644 --- a/src/models/items/riksdagen_documents.py +++ b/src/models/items/riksdagen_documents.py @@ -60,7 +60,6 @@ def fetch_based_on_label(self, suggestion: Suggestion = None, task: Task = None) SERVICE wikibase:label {{ bd:serviceParam wikibase:language "sv". }} }} """, - debug=suggestion.args.debug_sparql, ) for item_json in results["results"]["bindings"]: logging.debug(f"item_json:{item_json}") diff --git a/src/models/items/scholarly_articles.py b/src/models/items/scholarly_articles.py index c3a9bff..b97c6ec 100644 --- a/src/models/items/scholarly_articles.py +++ b/src/models/items/scholarly_articles.py @@ -154,7 +154,6 @@ def process_results(results): SERVICE wikibase:label {{ bd:serviceParam wikibase:language "en". }} }} """, - debug=suggestion.args.debug_sparql, ) logging.info( f'Got {len(results["results"]["bindings"])} preprint items from ' diff --git a/src/models/items/thesis.py b/src/models/items/thesis.py index ef30852..4e199cd 100644 --- a/src/models/items/thesis.py +++ b/src/models/items/thesis.py @@ -57,7 +57,6 @@ def fetch_based_on_label(self, suggestion: Suggestion = None, task: Task = None) SERVICE wikibase:label {{ bd:serviceParam wikibase:language "en". }} }} """, - debug=suggestion.args.debug_sparql, ) for item_json in results["results"]["bindings"]: logging.debug(f"item_json:{item_json}") diff --git a/src/models/login.py b/src/models/login.py new file mode 100644 index 0000000..afdf82f --- /dev/null +++ b/src/models/login.py @@ -0,0 +1,20 @@ +from wikibaseintegrator import wbi_login, wbi_config + +import config + + +class Login: + def __init__(self): + self.login() + + @staticmethod + def login(): + from src.helpers.console import console + + with console.status("Logging in with WikibaseIntegrator..."): + config.login_instance = wbi_login.Login( + user=config.username, + password=config.password, + ) + # Set User-Agent + wbi_config.config["USER_AGENT_DEFAULT"] = config.user_agent