def custom_generator(self): query = self.store.build_query('dupes', dupe=' wd:'.join(self.dupe_items), offset=self.offset) return WikidataSPARQLPageGenerator(query, site=self.repo, result_type=list)
def custom_generator(self): for prop in self.opt['props']: for key in ('duplicate_dates', 'unmerged_dates'): query = self.store.build_query(key, prop=prop, limit=self.opt['limit']) yield from WikidataSPARQLPageGenerator(query, site=self.repo)
def check_tv_show(tvshow_id=None, child_type="all", autofix=False, accumulate=False, interactive=False, filter=""): """Check constraints for season/episodes of this TV show Arguments --------- tvshow_id: str the Wiki ID of the television series, in the format Q######. child_type: str one of "episode", "season", "series", or "all" autofix: bool whether or not to attempt auto-fixing constraint failures accumulate: bool whether or not to accumulate all fixes before applying them to WikiData interactive: bool whether or not to prompt for confirmation before making edits filter: str a comma-separated list of properties in the format P###. Only edits for these properties will be applied. """ if child_type == "episode": instance_types = [wp.TELEVISION_SERIES_EPISODE] elif child_type == "season": instance_types = [wp.TELEVISION_SERIES_SEASON] elif child_type == "series": instance_types = [wp.TELEVISION_SERIES] elif child_type == "all": instance_types = [ wp.TELEVISION_SERIES, wp.TELEVISION_SERIES_SEASON, wp.TELEVISION_SERIES_EPISODE ] for instance_of_type in instance_types: key_val_pairs = { wp.PART_OF_THE_SERIES.pid: tvshow_id, wp.INSTANCE_OF.pid: instance_of_type } query = generate_sparql_query(key_val_pairs) gen = WikidataSPARQLPageGenerator(query) if instance_of_type == wp.TELEVISION_SERIES: gen = [ItemPage(Site().data_repository(), tvshow_id)] bot = getbot(gen, autofix=autofix, accumulate=accumulate, always=(not interactive), property_filter=filter) bot.run()
def previous_in_series(self) -> Optional[Season]: """The previous season from the same series""" if self.ordinal_in_series is None: return None query = f"""SELECT ?item WHERE {{ ?item wdt:{wp.INSTANCE_OF.pid} wd:{wp.TELEVISION_SERIES_SEASON}. ?item wdt:{wp.PART_OF_THE_SERIES.pid} wd:{self.series_qid}. ?item p:{wp.PART_OF_THE_SERIES.pid}/pq:{wp.SERIES_ORDINAL.pid} "{self.ordinal_in_series - 1}" }} """ gen = WikidataSPARQLPageGenerator(query) previous_season_itempage = next(gen, None) if previous_season_itempage is None: return None return Season(previous_season_itempage)
def next_in_series(self) -> Optional[Episode]: """The next Episode from the same series""" if self.ordinal_in_series is None: return None query = f"""SELECT ?item WHERE {{ ?item wdt:{wp.INSTANCE_OF.pid} wd:{wp.TELEVISION_SERIES_EPISODE}. ?item wdt:{wp.PART_OF_THE_SERIES.pid} wd:{self.series_qid}. ?item p:{wp.PART_OF_THE_SERIES.pid}/pq:{wp.SERIES_ORDINAL.pid} "{self.ordinal_in_series + 1}" }} """ gen = WikidataSPARQLPageGenerator(query) next_episode_itempage = next(gen, None) if next_episode_itempage is None: return None return Episode(next_episode_itempage)
def generator(self): step = self.getOption('step') opts = dict(blacklist=' wd:'.join(self.blacklist), limit=step) offset = self.getOption('offset') while True: pywikibot.output('\nLoading items (offset %i)...' % offset) opts['offset'] = offset ask = self.store.build_query('ask_externalid_props', **opts) if not self.sparql.ask(ask): break query = self.store.build_query('external-ids', **opts) gen = PreloadingEntityGenerator( WikidataSPARQLPageGenerator(query, site=self.repo)) for item in gen: yield item offset += step
def generator(self): step = self.opt['step'] opts = { # fixme: don't use this word 'blacklist': ' wd:'.join(self.blacklist), 'limit': step, } offset = self.opt['offset'] while True: pywikibot.output('\nLoading items (offset %i)...' % offset) opts['offset'] = offset ask = self.store.build_query('ask_externalid_props', **opts) if not self.sparql.ask(ask): break query = self.store.build_query('external-ids', **opts) gen = PreloadingEntityGenerator( WikidataSPARQLPageGenerator(query, site=self.repo)) yield from gen offset += step
def previous(self) -> Optional[Season]: """The previous season, if any""" # Check if it has the FOLLOWS field set previous_season_itempage = self.first_claim(wp.FOLLOWS.pid) if previous_season_itempage is not None: return Season(previous_season_itempage) # Find the item that has the FOLLOWED_BY field set to this item query = generate_sparql_query({wp.FOLLOWED_BY.pid: self.qid}) gen = WikidataSPARQLPageGenerator(query) follows = next(gen, None) if follows is not None: return Season(follows) # Find the item whose ordinal is one lower for this series if self.ordinal_in_series is not None: return self.previous_in_series return None
def next(self) -> Optional[Season]: """The next season, if any""" # Check if it has the FOLLOWED_BY field set next_season_itempage = self.first_claim(wp.FOLLOWED_BY.pid) if next_season_itempage is not None: return Season(next_season_itempage) # Find the item that has the FOLLOWS field set to this item query = generate_sparql_query({wp.FOLLOWS.pid: self.qid}) gen = WikidataSPARQLPageGenerator(query) is_followed_by = next(gen, None) if is_followed_by is not None: return Season(is_followed_by) # Find the item whose ordinal is one higher for this series if self.ordinal_in_series is not None: return self.next_in_series return None
def check_tv_show(tvshow_id=None, child_type="episode", autofix=False, accumulate=False, always=False, filter=""): """Check constraints for season/episodes of this TV show TVSHOW_ID is the ID of the television series, in the format Q######. """ if child_type == "episode": instance_types = [wp.TELEVISION_SERIES_EPISODE] elif child_type == "season": instance_types = [wp.TELEVISION_SERIES_SEASON] elif child_type == "series": instance_types = [wp.TELEVISION_SERIES] elif child_type == "all": instance_types = [ wp.TELEVISION_SERIES, wp.TELEVISION_SERIES_SEASON, wp.TELEVISION_SERIES_EPISODE ] for instance_of_type in instance_types: key_val_pairs = { wp.PART_OF_THE_SERIES.pid: tvshow_id, wp.INSTANCE_OF.pid: instance_of_type } query = generate_sparql_query(key_val_pairs) gen = WikidataSPARQLPageGenerator(query) if instance_of_type == wp.TELEVISION_SERIES: gen = [ItemPage(Site().data_repository(), tvshow_id)] bot = getbot(gen, autofix=autofix, accumulate=accumulate, always=always, property_filter=filter) bot.run()
def custom_generator(self): query = self.store.build_query('redirects', days=self.opt['days']) return WikidataSPARQLPageGenerator(query, site=self.repo)
def generator(self): query = self.store.build_query('missing_descriptions', hostname=self.site.hostname(), lang=self.site.lang) return PreloadingEntityGenerator( WikidataSPARQLPageGenerator(query, site=self.repo))
def custom_generator(self): for prop in self.props: query = self.store.build_query('duplicate_dates', prop=prop) for item in WikidataSPARQLPageGenerator(query, site=self.repo): yield item