Skip to content

Commit

Permalink
handle already existing reference nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Fossati committed Jul 25, 2019
1 parent 2b3f34b commit 3afa0e4
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions soweego/ingester/wikidata_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import click
import pywikibot
from pywikibot.exceptions import NoPage
from pywikibot.data.api import APIError

from soweego.commons import target_database
from soweego.commons.constants import QID_REGEX
Expand Down Expand Up @@ -650,32 +651,47 @@ def _reference(claim, stated_in, person_pid, person_tid):
STATED_IN_REFERENCE.setTarget(pywikibot.ItemPage(REPO, stated_in))

if None in (person_pid, person_tid):
claim.addSources([STATED_IN_REFERENCE, RETRIEVED_REFERENCE])

LOGGER.info(
'Added (%s, %s), (%s, %s) reference node',
STATED_IN_REFERENCE.getID(),
stated_in,
RETRIEVED_REFERENCE.getID(),
TODAY,
reference_log = (
f'({STATED_IN_REFERENCE.getID()}, {stated_in}), '
f'({RETRIEVED_REFERENCE.getID()}, {TODAY})'
)

try:
claim.addSources([STATED_IN_REFERENCE, RETRIEVED_REFERENCE])

LOGGER.info(
'Added %s reference node',
reference_log
)
except APIError as error:
LOGGER.warning(
'Could not add %s reference node: %s',
reference_log, error
)
else:
tid_reference = pywikibot.Claim(REPO, person_pid, is_reference=True)
tid_reference.setTarget(person_tid)

claim.addSources(
[STATED_IN_REFERENCE, tid_reference, RETRIEVED_REFERENCE]
reference_log = (
f'({STATED_IN_REFERENCE.getID()}, {stated_in}), '
f'({person_pid}, {person_tid}), '
f'({RETRIEVED_REFERENCE.getID()}, {TODAY})'
)

LOGGER.info(
'Added (%s, %s), (%s, %s), (%s, %s) reference node',
STATED_IN_REFERENCE.getID(),
stated_in,
person_pid,
person_tid,
RETRIEVED_REFERENCE.getID(),
TODAY,
)
try:
claim.addSources(
[STATED_IN_REFERENCE, tid_reference, RETRIEVED_REFERENCE]
)

LOGGER.info(
'Added %s reference node',
reference_log
)
except APIError as error:
LOGGER.warning(
'Could not add %s reference node: %s',
reference_log, error
)


def _delete_or_deprecate(action, qid, tid, catalog, catalog_pid) -> None:
Expand Down

0 comments on commit 3afa0e4

Please sign in to comment.