def treat_page(self): page = self.current_page code = mwparserfromhell.parse(page.text) for temp in code.ifilter_templates(): if self.template != self.normalize(temp.name): continue if not temp.has(self.param): continue param = temp.get(self.param) value = str(param.value) before, inside, after = self.handle_param(value) if not before and not after: continue temp.add(self.param, inside) if before: temp.add(self.param_before, before, before=param) my_param = temp.get(self.param_before) my_param.value = self.add_spaces(my_param.value, value) if after: index = temp.params.index(param) if len(temp.params) - 1 == index: temp.add(self.param_after, after) else: temp.add(self.param_after, after, before=temp.params[index+1]) my_param = temp.get(self.param_after) my_param.value = self.add_spaces(my_param.value, value) if self.put_current(str(code), summary=self.summary): self.offset -= 1
def treat_property_and_talk(self, prop, page): self.current_talk_page = page # todo: skip sandbox properties # todo: removeDisabledParts now? code = mwparserfromhell.parse(page.text, skip_style_tags=True) for template in code.ifilter_templates(): if not template.name.matches(self.template_metadata): continue params = OrderedDict() for param in template.params: params[str(param.name).strip()] = str(param.value).strip() break else: pywikibot.output('Template "{}" not found'.format( self.template_metadata)) return keys = set(self.func_dict.keys()) & set(params.keys()) # formatter URL must go before example if {'formatter URL', 'example'} <= keys: keys.remove('formatter URL') keys = ['formatter URL'] + list(keys) clear_params = [] for key in keys: param = textlib.removeDisabledParts(params[key]) if param == '-': continue if param != '': pywikibot.output('Found param "{}"'.format(key)) try: remove = self.func_dict[key](param) except pywikibot.data.api.APIError as exc: remove = False if remove: clear_params.append(key) if self.getOption('importonly'): return for par in clear_params: template.remove(par, keep_field=True) for par in set(params.keys()) & set(self.obsolete_params): template.remove(par) self.current_page = self.current_talk_page self.put_current(str(code), show_diff=True, summary='removing migrated/obsolete parameters')
genFactory.handleArg(arg) generator = genFactory.getCombinedGenerator(preload=True) if not generator: genFactory.handleArg('-cat:Seznamy památných stromů v Česku podle okresů') generator = genFactory.getCombinedGenerator(preload=True) # todo: cache all in a single query query = '''SELECT DISTINCT ?item { { ?item wdt:P3296 "%s" } UNION { ?item wdt:P677 "%s" } } LIMIT 2''' titleR = re.compile(r'(\s*)([^[|\]<>]+?)((?: *†| *\(x\))?\s*)') for page in generator: pywikibot.output(page) code = parser.parse(page.text) change = False for table in code.ifilter_tags(matches=lambda t: t.tag == 'table'): rows = table.contents.ifilter_tags(matches=lambda t: t.tag == 'tr') first = next(rows) index = {key: None for key in ('název', 'obrázek', 'kód')} for i, cell in enumerate( first.contents.ifilter_tags(matches=lambda t: t.tag == 'th')): for key, value in index.items(): if value is None and key in str(cell.contents).lower(): index[key] = i break for key, value in index.items(): if value is None: pywikibot.output("Couldn't determine column for '%s'" % key) if index['kód'] is None: