def fix(item: model.television.Season) -> Iterable[api.Fix]: claim_fixes = [] for ordinal, episode in item.parts: qualifier = Claim(item.repo, wp.SERIES_ORDINAL.pid) qualifier.setTarget(str(ordinal)) new_claim = Claim(item.repo, wp.HAS_PART.pid) new_claim.setTarget(episode.itempage) new_claim.addQualifier(qualifier) summary = f"Adding {episode.qid} to {wp.HAS_PART.pid} ({wp.HAS_PART.name})" claim_fixes.append(api.ClaimFix(new_claim, summary, item.itempage)) return claim_fixes
def get_or_create_qualifiers(claim: Claim, p_value: str, value: Any) -> Claim: """ Gets or creates a `qualifier` under the property `p_value` to `claim` """ all_qualifiers = claim.qualifiers.get(p_value, []) for qualifier in all_qualifiers: if qualifier.target_equals(value): break else: qualifier = Claim(Settings.wikidata_repo, p_value) qualifier.setTarget(value) claim.addQualifier(qualifier) return qualifier