Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #57
Browse files Browse the repository at this point in the history
Refactor login and update to new WBI syntax
  • Loading branch information
dpriskorn authored Apr 11, 2022
2 parents 5248a8b + c234bd8 commit b2f9242
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
13 changes: 0 additions & 13 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}")
Expand Down
7 changes: 4 additions & 3 deletions src/models/batch_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion src/models/items/academic_journals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down
1 change: 0 additions & 1 deletion src/models/items/riksdagen_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
1 change: 0 additions & 1 deletion src/models/items/scholarly_articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down
1 change: 0 additions & 1 deletion src/models/items/thesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
20 changes: 20 additions & 0 deletions src/models/login.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b2f9242

Please sign in to comment.