Example #1
0
 def make_magazines(self, dictionary_of_magazines_by_year):
     for idx_year, year in enumerate(dictionary_of_magazines_by_year):
         magazines = dictionary_of_magazines_by_year[year]
         self.logger.debug(f"make_mag_year {idx_year + 1}/"
                           f"{len(dictionary_of_magazines_by_year)}")
         for idx_mag, magazine in enumerate(magazines):
             self.logger.debug("make_mag_mag {idx}/{len} ... issue:{year}/{mag}"
                               .format(idx=idx_mag + 1, len=len(magazines),
                                       year=year, mag=magazine))
             if year == "1986" and magazine == "31":
                 self.logger.warning("There is magazine 1986, 31, "
                                     "this is special, no creating here")
                 continue
             if self.debug:
                 lemma = Page(self.wiki, "Benutzer:THEbotIT/Test")
             else:
                 lemma = Page(self.wiki, f"Die Gartenlaube ({year})/Heft {int(magazine):d}")
             new_text = self.make_magazine(year, magazine)
             if new_text:
                 if hash(new_text.strip()) != hash(lemma.text.strip()):
                     self.logger.debug("Print [[Die Gartenlaube ({year})/Heft {magazine}]]."
                                       .format(year=year, magazine=magazine))
                     if lemma.text != '':
                         lemma.text = new_text
                         lemma.save("Automatische Aktualisierung des Heftes", botflag=True)
                     else:
                         lemma.text = new_text
                         lemma.save("automatische Hefterstellung", botflag=True)
                 else:
                     self.logger.debug("Keine Änderung im Text ({year}/{magazine})."
                                       .format(year=year, magazine=magazine))
Example #2
0
    def task(self):
        list_platzhalter = []
        list_protected = []
        lemma_list = self.get_list()
        for idx, item in enumerate(lemma_list):
            lemma = Page(self.wiki, item["title"])
            if self.is_protected(lemma):
                list_protected.append(lemma.title())
                lemma.protect(protections={
                    "edit": "autoconfirmed",
                    "move": "autoconfirmed"
                },
                              reason="is now common")
            categories = [item.title() for item in lemma.categories()]
            if "Kategorie:RE:Platzhalter" in categories:
                list_platzhalter.append(lemma.title())
            self.logger.info(
                f"{idx}/{len(lemma_list)} prot: {len(list_protected)}, plat: {len(list_platzhalter)} {lemma.title()}"
            )

        page_protected = Page(self.wiki,
                              "Benutzer:THE IT/RE/Arthur Stein/protected")
        page_protected.text = self.join_lists(list_protected)
        page_protected.save()

        page_platzhalter = Page(self.wiki,
                                "Benutzer:THE IT/RE/Arthur Stein/platzhalter")
        page_platzhalter.text = self.join_lists(list_platzhalter)
        page_platzhalter.save()
        return True
Example #3
0
def add_old_cfd(
    page: pywikibot.Page,
    cfd_page: CfdPage,
    action: str,
    result: str,
    summary: str,
) -> None:
    """Add {{Old CfD}} to the talk page."""
    date = cfd_page.title(with_section=False).rpartition('/')[2]
    if page.exists():
        wikicode = mwparserfromhell.parse(page.text, skip_style_tags=True)
        for tpl in wikicode.ifilter_templates():
            try:
                template = pywikibot.Page(page.site, str(tpl.name), ns=10)
                if template not in TPL['old cfd'] or not tpl.has(
                        'date', ignore_empty=True):
                    continue
            except pywikibot.InvalidTitle:
                continue
            if tpl.get('date').value.strip() == date:
                # Template already present.
                return
    old_cfd = Template('Old CfD')
    old_cfd.add('action', action)
    old_cfd.add('date', date)
    old_cfd.add('section', cfd_page.section())
    old_cfd.add('result', result)
    page.text = str(old_cfd) + '\n' + page.text
    page.save(summary=summary)
Example #4
0
    def user_page_the_it(self, korrigiert: Tuple[int, int]):
        status_string = []

        color = make_html_color(20e6, 22e6, korrigiert[0])
        status_string.append(
            f"<span style=\"background:#FF{color}{color}\">{korrigiert[0]}</span>"
        )
        color = make_html_color(5.0e3, 5.25e3, korrigiert[1])
        status_string.append(
            f"<span style=\"background:#FF{color}{color}\">{korrigiert[1]}</span>"
        )

        list_of_lemmas = self.petscan(["RE:Teilkorrigiert", "RE:Korrigiert"],
                                      ["RE:Unkorrigiert", "RE:Unvollständig"])
        date_page = Page(self.wiki, list_of_lemmas[0]["title"])
        date_of_first = str(date_page.oldest_revision.timestamp)[0:10]
        gap = datetime.now() - datetime.strptime(date_of_first, "%Y-%m-%d")
        color = make_html_color(3 * 365, 3.5 * 365, gap.days)
        status_string.append(
            f"<span style=\"background:#FF{color}{color}\">{date_of_first}</span>"
        )

        user_page = Page(self.wiki, "Benutzer:THE IT/Werkstatt")
        temp_text = user_page.text
        temp_text = re.sub(r"<!--RE-->.*<!--RE-->",
                           f"<!--RE-->{' ■ '.join(status_string)}<!--RE-->",
                           temp_text)
        user_page.text = temp_text
        user_page.save("todo RE aktualisiert")
Example #5
0
    def generate_overviews(self):
        """Create page on wikis with overview of bot results."""
        for site in self.sites:
            sync_overview_page = Page(site,
                                      'User:{0}/sync.py overview'
                                      .format(site.user()))
            output = '== Pages that differ from original ==\n\n'
            if self.differences[site]:
                output += ''.join('* [[:%s]]\n' % l for l in
                                  self.differences[site])
            else:
                output += 'All important pages are the same'

            output += (
                '\n\n== Admins from original that are missing here ==\n\n')
            if self.user_diff[site]:
                output += ''.join('* %s\n' % l.replace('_', ' ') for l in
                                  self.user_diff[site])
            else:
                output += (
                    'All users from original are also present on this wiki')

            pywikibot.output(output)
            sync_overview_page.text = output
            sync_overview_page.save(self.put_message(site))
Example #6
0
    def _add_category_page(self, title, categories):
        """Add a page with categories.

        Parameters
        ----------
        title : str
            Title of the page.
        categories : list
            The categories to add to the page.

        """

        page = Page(self._site, title, "Category")
        if page.exists() and not self._overwrite:
            logging.warning(
                "Category page '{}' already exists. It will not be created.".
                format(page.title())  # noqa: E501
            )
        else:
            page.text = ""
            for category in categories:
                if category != title:
                    page.text += "[[Kategori:{}]]\n".format(category)
            logging.info("Writing to category page '{}'".format(page.title()))
            logging.debug(page.text)
            self._write_page(page)
Example #7
0
def trySaving(page: pywikibot.Page,
              content: str,
              summary: str,
              overwrite: bool,
              limitType: str = 'default') -> bool:
    """Create or overwrite page with given content, checking bot limits.

    Summary is prepended with link to BRFA and appended with 'Report problems'.
    """
    global _editsDone  # pylint: disable=global-statement
    if limitType not in _editsLimits or limitType not in _editsDone:
        raise Exception(f'Undefined limit type: "{limitType}"')
    if _editsDone[limitType] >= _editsLimits[limitType]:
        return False
    _editsDone[limitType] += 1
    if _onlySimulateEdits:
        return False
    page.text = content
    summary = (f'[[Wikipedia:Bots/Requests_for_approval/'
               f'{_botName}_{_brfaNumber}|({_brfaNumber})]] '
               f'{summary} [[User talk:TokenzeroBot|Report problems]]')
    page.save(summary,
              minor=False,
              botflag=True,
              watch="nochange",
              createonly=False if overwrite else True,
              nocreate=True if overwrite else False,
              tags='bot trial' if _botTrial else None)
    return True
Example #8
0
 def get_all_sites(self):
     dummypage = Page(self.wiki, 'Benutzer:THEbotIT/dummy')
     dummypage.text = '{{subst:NUMBEROFARTICLES}}'
     dummypage.save('get_new_number')
     del dummypage
     dummypage = Page(self.wiki, 'Benutzer:THEbotIT/dummy')
     return '{}'.format(dummypage.text)
Example #9
0
 def get_wiki_bearbeitungen(self):
     dummypage = Page(self.wiki, 'Benutzer:THEbotIT/dummy')
     dummypage.text = '{{subst:NUMBEROFEDITS}}'
     dummypage.save('get_new_number')
     del dummypage
     dummypage = Page(self.wiki, 'Benutzer:THEbotIT/dummy')
     return dummypage.text
Example #10
0
    def _add_page_from_template(self, namespace, title, template_name,
                                template_parameters):
        """Add a page by substituting a template.

        Parameters
        ----------
        namespace : str
            Namespace of the page. If None, the default namespace will
            be used.
        title : str
            The title of the page.
        template_name : str
            The name of the template to substitute to create the subpage.
        template_parameters : list or OrderedDict
            Parameters to pass to the template.

        """

        if namespace is None:
            page = Page(self._site, title)
        else:
            page = Page(self._site, title, namespace)
        if page.exists() and not self._overwrite:
            logging.warning(
                "Page '{}' already exists. It will not be created.".format(
                    page.title()))
        else:
            template = Template(template_name, True, template_parameters)
            page.text = template.multiline_string()
            logging.info("Writing to page '{}'.".format(page.title()))
            logging.debug(page.text)
            self._write_page(page)
Example #11
0
 def get_all_sites(self):
     dummypage = Page(self.wiki, 'Benutzer:THEbotIT/dummy')
     dummypage.text = '{{subst:NUMBEROFARTICLES}}'
     dummypage.save('get_new_number')
     del dummypage
     dummypage = Page(self.wiki, 'Benutzer:THEbotIT/dummy')
     return '{}'.format(dummypage.text)
Example #12
0
 def task(self):  # pragma: no cover
     page = Page(self.wiki, "Benutzer:THE IT/Werkstatt")
     new_text = self.replace_in_page(page.text)
     page.text = new_text
     if not self.debug:
         page.save("Time is ticking")
     return True
Example #13
0
    def userPut(
        self,
        page: pywikibot.Page,
        oldtext: str,
        newtext: str,
        summary: Optional[str] = None,
        minor: bool = True,
        botflag: Optional[bool] = None,
    ) -> None:
        if oldtext == newtext:
            pywikibot.output("No changes were needed on %s" % page.title(as_link=True))
            return

        pywikibot.output("\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title(as_link=True))

        pywikibot.showDiff(oldtext, newtext)
        if summary:
            pywikibot.output("Summary: %s" % summary)

        page.text = newtext
        try:
            page.save(summary=summary, minor=minor, botflag=botflag)
        except pywikibot.EditConflict:
            raise
        except pywikibot.Error as e:
            pywikibot.output("Failed to save %s: %r: %s" % (page.title(as_link=True), e, e))
Example #14
0
 def get_wiki_bearbeitungen(self):
     dummypage = Page(self.wiki, 'Benutzer:THEbotIT/dummy')
     dummypage.text = '{{subst:NUMBEROFEDITS}}'
     dummypage.save('get_new_number')
     del dummypage
     dummypage = Page(self.wiki, 'Benutzer:THEbotIT/dummy')
     return dummypage.text
def save_page(
    text: str,
    page: pywikibot.Page,
    summary: str,
    bot: bool = True,
    minor: bool = False,
    mode: str = "replace",
) -> None:
    logger.info(f"Saving to {page.title()}")
    if not text:
        raise pywikibot.PageNotSaved(
            page, message="New page text is blank, page %s was not saved")

    if mode == "replace":
        text = text
    elif mode == "append":
        text = page.get(force=True) + text
    elif mode == "prepend":
        text = text + page.get(force=True)
    else:
        raise ValueError(
            "mode must be 'replace', 'append', or 'prepend', not {mode}")

    if page.get(force=True) == text:
        raise pywikibot.PageNotSaved(
            page, message="Page text did not change, page %s was not saved")
    else:
        page.text = text
        page.save(
            summary=summary,
            minor=minor,
            botflag=bot,
            quiet=True,
        )
        logger.info(f"Page {page.title(as_link=True)} saved")
Example #16
0
 def finish_task(self):
     if self.data:
         if not self.debug:
             page = Page(self.wiki, "RE:Wartung:Strukturfehler")
             page.text = page.text + self._build_entry()
             page.save("Neue Fehlermeldungen", botflag=True)
     super().finish_task()
Example #17
0
    def task(self):
        if self.debug:  # activate for debug purpose
            lemma = "Benutzer:THEbotIT/" + self.bot_name
        else:
            lemma = "Die Gartenlaube"
        page = Page(self.wiki, lemma)
        temp_text = page.text

        alle = self.petscan([])
        fertig = self.petscan(["Fertig"])
        korrigiert = self.petscan(["Korrigiert"])
        unkorrigiert = self.petscan(["Unkorrigiert"])
        articles = self.petscan([],
                                article=True,
                                not_categories=["Die Gartenlaube Hefte"])

        temp_text = self.projektstand(temp_text, alle, fertig, korrigiert,
                                      unkorrigiert, articles)
        temp_text = self.alle_seiten(temp_text, alle)
        temp_text = self.korrigierte_seiten(temp_text, korrigiert)
        temp_text = self.fertige_seiten(temp_text, fertig)
        for year in range(1853, 1900):
            temp_text = self.year(year, temp_text)

        page.text = temp_text
        page.save("Ein neuer Datensatz wurde eingefügt.", botflag=True)
        return True
Example #18
0
 def task(self):  # pragma: no cover
     page = Page(self.wiki, "Benutzer:THE IT/Werkstatt")
     new_text = self.replace_in_page(page.text)
     page.text = new_text
     if not self.debug:
         page.save("Time is ticking")
     return True
Example #19
0
 def logGroup(self, page: pywikibot.Page,
              users: List[pywikibot.User]) -> None:
     text = page.get(force=True) if page.exists() else ""
     for user in users:
         newLine = f"\n* [[Benutzer:{user.username}|{user.username}]]"
         if not newLine in text:
             text += newLine
     page.text = text
     page.save(summary=f"Bot: Benutzerliste nach Botlauf aktualisiert.")
 def task(self):
     for idx, item in enumerate(self.get_list()):
         lemma = Page(self.wiki, item["title"])
         temp_text = lemma.text
         for cat in self.cat_list:
             temp_text = re.sub(f"\[\[Kategorie:{cat}\]\]\n?", "",
                                temp_text)
         lemma.text = temp_text
         lemma.save("remove categories")
     return True
Example #21
0
 def make_magazines(self, dictionary_of_magazines_by_year):
     for idx_year, year in enumerate(dictionary_of_magazines_by_year):
         magazines = dictionary_of_magazines_by_year[year]
         self.logger.debug(f"make_mag_year {idx_year + 1}/"
                           f"{len(dictionary_of_magazines_by_year)}")
         for idx_mag, magazine in enumerate(magazines):
             self.logger.debug(
                 f"make_mag_mag {idx_mag + 1}/{len(magazines)} ... issue:{year}/{magazine}"
             )
             if year == "1986" and magazine == "31":
                 self.logger.warning(
                     "There is magazine 1986, 31, this is special, no creating here"
                 )
                 continue
             if self.debug:
                 lemma = Page(self.wiki, "Benutzer:THEbotIT/Test")
             else:
                 lemma = Page(
                     self.wiki,
                     f"Die Gartenlaube ({year})/Heft {int(magazine):d}")
             new_text = self.make_magazine(year, magazine)
             if new_text:
                 if hash(new_text.strip()) != hash(lemma.text.strip()):
                     self.logger.debug(
                         f"Print [[Die Gartenlaube ({year})/Heft {magazine}]]."
                     )
                     if lemma.text != '':
                         lemma.text = new_text
                         lemma.save(
                             "Automatische Aktualisierung des Heftes",
                             botflag=True)
                     else:
                         lemma.text = new_text
                         lemma.save("automatische Hefterstellung",
                                    botflag=True)
                 else:
                     self.logger.debug(
                         f"Keine Änderung im Text ({year}/{magazine}).")
Example #22
0
 def history(self, fertig, korrigiert, unkorrigiert):
     page = Page(self.wiki, "Benutzer:THEbotIT/" + self.bot_name)
     temp_text = page.text
     composed_text = "".join(["|-\n", "|", self.timestamp.start_of_run.strftime("%Y%m%d-%H%M"),
                              "||", str(unkorrigiert[1]), "||", str(unkorrigiert[0]),
                              "||", str(int(unkorrigiert[0] / unkorrigiert[1])),
                              "||", str(korrigiert[1]), "||", str(korrigiert[0]),
                              "||", str(int(korrigiert[0] / korrigiert[1])),
                              "||", str(fertig[1]), "||", str(fertig[0]),
                              "||", str(int(fertig[0] / fertig[1])),
                              "\n<!--new line-->"])
     temp_text = re.sub("<!--new line-->", composed_text, temp_text)
     page.text = temp_text
     page.save("RE Statistik aktualisiert", botflag=True)
Example #23
0
 def task(self):  # pragma: no cover
     regex = re.compile(r"\n\|PND=")
     searcher = PetScan()
     searcher.add_yes_template("ADBDaten")
     searcher.add_positive_category("ADB:Ohne GND-Link")
     lemma_list = searcher.run()
     for lemma in lemma_list:
         page = Page(self.wiki, lemma["title"])
         temp_text = page.text
         if regex.search(temp_text):
             self.logger.info(f"change {lemma['title']}")
             temp_text = regex.sub("\n|GND=", temp_text)
         page.text = temp_text
         page.save("PND -> GND", botflag=True)
     return True
Example #24
0
 def task(self):
     lemma_list = self._run_searcher()
     self._build_database(lemma_list)
     if self.debug:
         dump = Page(self.wiki, f"Benutzer:THEbotIT/{self.bot_name}")
     else:
         dump = Page(self.wiki, "Liste der Autoren")
     old_text = dump.text
     new_text = self._convert_to_table()
     if new_text[150:] != old_text[150:]:  # compare all but the date
         dump.text = new_text
         dump.save("Die Liste wurde auf den aktuellen Stand gebracht.", botflag=True)
     else:
         self.logger.info("Heute gab es keine Änderungen, "
                          "daher wird die Seite nicht überschrieben.")
     return True
Example #25
0
 def task(self):
     lemma_list = self._run_searcher()
     self._build_database(lemma_list)
     if self.debug:
         dump = Page(self.wiki, f"Benutzer:THEbotIT/{self.bot_name}")
     else:
         dump = Page(self.wiki, "Liste der Autoren")
     old_text = dump.text
     new_text = self._convert_to_table()
     if new_text[150:] != old_text[150:]:  # compare all but the date
         dump.text = new_text
         dump.save("Die Liste wurde auf den aktuellen Stand gebracht.",
                   botflag=True)
     else:
         self.logger.info("Heute gab es keine Änderungen, "
                          "daher wird die Seite nicht überschrieben.")
     return True
 def task(self):  # pragma: no cover
     error_task = ERROTask(wiki=self.wiki, debug=False, logger=self.logger)
     for lemma in self.search_pages():
         page = Page(self.wiki, lemma["title"])
         temp_text = page.text
         try:
             temp_text = self.convert_all(temp_text)
             page.text = temp_text
             re_page = RePage(page)
             if not self.debug:
                 re_page.save("Entfernen veralteter Vorlagen.")
         except (ReDatenException, ValueError):
             error = traceback.format_exc().splitlines()[-1]
             error_task.task(lemma["title"], error)
     error_task.finish_task()
     if self.search_pages():
         return False
     return True
Example #27
0
 def task(self):  # pragma: no cover
     error_task = ERROTask(wiki=self.wiki, debug=False, logger=self.logger)
     for lemma in self.search_pages():
         page = Page(self.wiki, lemma["title"])
         temp_text = page.text
         try:
             temp_text = self.convert_all(temp_text)
             page.text = temp_text
             re_page = RePage(page)
             if not self.debug:
                 re_page.save("Entfernen veralteter Vorlagen.")
         except (ReDatenException, ValueError):
             error = traceback.format_exc().splitlines()[-1]
             error_task.task(lemma["title"], error)
     error_task.finish_task()
     if self.search_pages():
         return False
     return True
Example #28
0
    def check_page(self, pagename):
        """Check one page."""
        pywikibot.output("\nChecking %s" % pagename)
        sys.stdout.flush()
        page1 = Page(self.original, pagename)
        txt1 = page1.text

        if self.options.dest_namespace:
            dest_ns = int(self.options.dest_namespace)
        else:
            dest_ns = None

        for site in self.sites:
            if dest_ns is not None:
                page2 = Page(site, page1.title(withNamespace=False), dest_ns)
                pywikibot.output("\nCross namespace, new title: %s"
                                 % page2.title())
            else:
                page2 = Page(site, pagename)

            if page2.exists():
                txt2 = page2.text
            else:
                txt2 = ''

            if str(site) in config.replicate_replace:
                txt_new = multiple_replace(txt1,
                                           config.replicate_replace[str(site)])
                if txt1 != txt_new:
                    pywikibot.output(
                        'NOTE: text replaced using config.sync_replace')
                    pywikibot.output('%s %s %s' % (txt1, txt_new, txt2))
                    txt1 = txt_new

            if txt1 != txt2:
                pywikibot.output("\n %s DIFFERS" % site)
                self.differences[site].append(pagename)

        if self.options.replace:
            page2.text = txt1
            page2.save(self.put_message(site))
        else:
            sys.stdout.write('.')
            sys.stdout.flush()
    def check_page(self, pagename):
        """Check one page."""
        pywikibot.output('\nChecking ' + pagename)
        sys.stdout.flush()
        page1 = Page(self.original, pagename)
        txt1 = page1.text

        if self.options.dest_namespace:
            dest_ns = int(self.options.dest_namespace)
        else:
            dest_ns = None

        for site in self.sites:
            if dest_ns is not None:
                page2 = Page(site, page1.title(with_ns=False), dest_ns)
                pywikibot.output('\nCross namespace, new title: ' +
                                 page2.title())
            else:
                page2 = Page(site, pagename)

            if page2.exists():
                txt2 = page2.text
            else:
                txt2 = ''

            if str(site) in config.replicate_replace:
                txt_new = multiple_replace(txt1,
                                           config.replicate_replace[str(site)])
                if txt1 != txt_new:
                    pywikibot.output(
                        'NOTE: text replaced using config.sync_replace')
                    pywikibot.output('{0} {1} {2}'.format(txt1, txt_new, txt2))
                    txt1 = txt_new

            if txt1 != txt2:
                pywikibot.output('\n {0} DIFFERS'.format(site))
                self.differences[site].append(pagename)

        if self.options.replace:
            page2.text = txt1
            page2.save(self.put_message(site))
        else:
            sys.stdout.write('.')
            sys.stdout.flush()
Example #30
0
    def check_page(self, pagename):
        """Check one page."""
        pywikibot.output("\nChecking %s" % pagename)
        sys.stdout.flush()
        page1 = Page(self.original, pagename)
        txt1 = page1.text

        for site in self.sites:
            if self.options.dest_namespace:
                prefix = namespaces(site)[int(self.options.dest_namespace)]
                if prefix:
                    prefix += ':'
                new_pagename = prefix + page1.titleWithoutNamespace()
                pywikibot.output("\nCross namespace, new title: %s" %
                                 new_pagename)
            else:
                new_pagename = pagename

            page2 = Page(site, new_pagename)
            if page2.exists():
                txt2 = page2.text
            else:
                txt2 = ''

            if str(site) in config.replicate_replace:
                txt_new = multiple_replace(txt1,
                                           config.replicate_replace[str(site)])
                if txt1 != txt_new:
                    pywikibot.output(
                        'NOTE: text replaced using config.sync_replace')
                    pywikibot.output('%s %s %s' % (txt1, txt_new, txt2))
                    txt1 = txt_new

            if txt1 != txt2:
                pywikibot.output("\n %s DIFFERS" % site)
                self.differences[site].append(pagename)

        if self.options.replace:
            page2.text = txt1
            page2.save(self.put_message(site))
        else:
            sys.stdout.write('.')
            sys.stdout.flush()
 def task(self):
     lemma_list = self._search()
     for idx, lemma in enumerate(lemma_list):
         page = Page(self.wiki, title='Index:{}'.format(lemma['title']))
         self.logger.info('{}/{}:{}'.format(idx, len(lemma_list), page))
         match = regex_picture.search(page.text)
         if match:
             self.logger.info(match.group(1))
             temp = re.sub('\|\d{2,3}px', '', match.group(1))
             if not re.search('thumb', match.group(1)):
                 temp = temp + '|thumb'
             self.logger.info(temp)
             if temp == match.group(1):
                 self.logger.info('nothing to do here.')
                 continue
             temp = '|BILD=[[{}]]'.format(temp)
             temp_text = regex_picture.sub(temp, page.text)
             page.text = temp_text
             page.save(botflag=True, summary='set thumb as parameter')
     return True
Example #32
0
def main():
    page = Page(site, "Star Wars Wiki:Apêndice de Tradução de obras/JSON")

    fixes = {}
    with open("bot/user-fixes.py") as f:
        exec(f.read(
        ))  # Can't import it normally because of naming and undefined variable

    if not 'obras' in fixes:
        raise Exception('Obras dictionary not found')

    fixes_json = json.dumps(fixes['obras'], ensure_ascii=False, indent=4)
    new_text = "<pre>{}</pre>".format(fixes_json.replace('\\\\1', '$1'))

    showDiff(page.text, new_text)
    if get_user_yes_or_no("Salvar?"):
        page.text = new_text
        page.save(
            "([[User:Thales César|Thales]]) 2.2 Atualizado com novas informações"
        )
Example #33
0
 def task(self):
     lemma_list = self._search()
     for idx, lemma in enumerate(lemma_list):
         page = Page(self.wiki, title='Index:{}'.format(lemma['title']))
         self.logger.info('{}/{}:{}'.format(idx, len(lemma_list), page))
         match = regex_picture.search(page.text)
         if match:
             self.logger.info(match.group(1))
             temp = re.sub('\|\d{2,3}px', '', match.group(1))
             if not re.search('thumb', match.group(1)):
                 temp = temp + '|thumb'
             self.logger.info(temp)
             if temp == match.group(1):
                 self.logger.info('nothing to do here.')
                 continue
             temp = '|BILD=[[{}]]'.format(temp)
             temp_text = regex_picture.sub(temp, page.text)
             page.text = temp_text
             page.save(botflag=True, summary='set thumb as parameter')
     return True
Example #34
0
 def history(self, fertig: Tuple[int, int], korrigiert: Tuple[int, int],
             unkorrigiert: Tuple[int, int]):
     page = Page(self.wiki, "Benutzer:THEbotIT/" + self.bot_name)
     temp_text = page.text
     composed_text = "".join([
         "|-\n", "|",
         self.timestamp.start_of_run.strftime("%Y%m%d-%H%M"), "||",
         str(unkorrigiert[1]), "||",
         str(unkorrigiert[0]), "||",
         str(int(unkorrigiert[0] / unkorrigiert[1])), "||",
         str(korrigiert[1]), "||",
         str(korrigiert[0]), "||",
         str(int(korrigiert[0] / korrigiert[1])), "||",
         str(fertig[1]), "||",
         str(fertig[0]), "||",
         str(int(fertig[0] / fertig[1])), "\n<!--new line-->"
     ])
     temp_text = re.sub("<!--new line-->", composed_text, temp_text)
     page.text = temp_text
     page.save("RE Statistik aktualisiert", botflag=True)
Example #35
0
def save_page(page_name: str, text: str, sheet_name: str,
              template_name: str) -> None:
    '''実際に wiki のページを書き込む'''
    if template_name is None:
        template_name = page_name

    # Bot 編集ページであることを知らせるフッターを付加して更新する
    sheet_url = get_sheet_url(sheet_name)
    footer = '\n\n{{bot/編集の注意|template_name = %s | url = %s}}' \
                                              % (template_name, sheet_url)
    text += footer

    # ページに変更がない場合には何もしない
    page = Page(site, page_name)
    if page.text == text:
        return

    page.text = text
    if args.debug:
        print(page.text)
    else:
        page.save()
Example #36
0
    def generate_overviews(self):
        """Create page on wikis with overview of bot results."""
        for site in self.sites:
            sync_overview_page = Page(site,
                                      'User:%s/sync.py overview' % site.user())
            output = "== Pages that differ from original ==\n\n"
            if self.differences[site]:
                output += "".join('* [[:%s]]\n' % l for l in
                                  self.differences[site])
            else:
                output += "All important pages are the same"

            output += "\n\n== Admins from original that are missing here ==\n\n"
            if self.user_diff[site]:
                output += "".join('* %s\n' % l.replace('_', ' ') for l in
                                  self.user_diff[site])
            else:
                output += "All users from original are also present on this wiki"

            pywikibot.output(output)
            sync_overview_page.text = output
            sync_overview_page.save(self.put_message(site))
Example #37
0
    def user_page_the_it(self, korrigiert):
        status_string = []

        color = make_html_color(20e6, 22e6, korrigiert[0])
        status_string.append(f"<span style=\"background:#FF{color}{color}\">{korrigiert[0]}</span>")
        color = make_html_color(5.0e3, 5.25e3, korrigiert[1])
        status_string.append(f"<span style=\"background:#FF{color}{color}\">{korrigiert[1]}</span>")

        list_of_lemmas = self.petscan(["RE:Teilkorrigiert", "RE:Korrigiert"],
                                      ["RE:Unkorrigiert", "RE:Unvollständig"])
        date_page = Page(self.wiki, list_of_lemmas[0]["title"])
        date_of_first = str(date_page.oldest_revision.timestamp)[0:10]
        gap = datetime.now() - datetime.strptime(date_of_first, "%Y-%m-%d")
        color = make_html_color(3 * 365, 3.5 * 365, gap.days)
        status_string.append(f"<span style=\"background:#FF{color}{color}\">{date_of_first}</span>")

        user_page = Page(self.wiki, "Benutzer:THE IT/Werkstatt")
        temp_text = user_page.text
        temp_text = re.sub(r"<!--RE-->.*<!--RE-->",
                           f"<!--RE-->{' ■ '.join(status_string)}<!--RE-->",
                           temp_text)
        user_page.text = temp_text
        user_page.save("todo RE aktualisiert")
Example #38
0
    def _create_current_projects_template(self):
        """Create a current projects template with the new projects."""
        page_name = self._make_year_title(
            self._config["year_pages"]["current_projects_template"])
        page = Page(self._site, page_name)
        if page.exists() and not self._overwrite:
            logging.warning(
                "Page '{}' already exists. It will not be created.".format(
                    page.title()))
            return

        project_format = "[[{ns}:{{proj}}|{{proj}}]]".format(
            ns=self._config["project_namespace"])
        delimiter = "''' · '''"
        template_data = {}
        for program in self._programs:
            projects = set()
            for strategy in program.get('strategies'):
                # projects sorted by id to get thematic grouping
                projects.update(strategy.get("projects"))
            template_data[program.get('name')] = delimiter.join([
                project_format.format(proj=self._projects[project])
                for project in sorted(projects)
            ])

        template = Template("Aktuella projekt/layout")
        template.add_parameter("år", self._year)
        template.add_parameter("access", template_data["Tillgång"])
        template.add_parameter("use", template_data["Användning"])
        template.add_parameter("community", template_data["Gemenskapen"])
        template.add_parameter("enabling", template_data["Möjliggörande"])

        page.text = template.multiline_string() + \
            "\n<noinclude>{{Dokumentation}}</noinclude>"
        logging.info("Writing to page '{}'.".format(page.title()))
        logging.debug(page.text)
        self._write_page(page)
Example #39
0
def remove_cfd_tpl(page: pywikibot.Page, summary: str) -> None:
    """
    Remove the CfD template from the page.

    @param page: Page to edit
    @param summary: Edit summary
    """
    text = re.sub(
        r'<!--\s*BEGIN CFD TEMPLATE\s*-->.*?'
        r'<!--\s*END CFD TEMPLATE\s*-->\n*',
        '',
        page.get(force=True),
        flags=re.I | re.M | re.S,
    )
    wikicode = mwparserfromhell.parse(text, skip_style_tags=True)
    for tpl in wikicode.ifilter_templates():
        try:
            template = pywikibot.Page(page.site, str(tpl.name), ns=10)
            if template in TPL['cfd']:
                wikicode.remove(tpl)
        except pywikibot.InvalidTitle:
            continue
    page.text = str(wikicode).strip()
    page.save(summary=summary)
def handle_maariv_paper_page(paper_page: pw.Page) -> None:
    publish_date = _extract_paper_page_from_title(paper_page.title())
    if publish_date is None:
        return

    parsed_mw_text = mwparserfromhell.parse(paper_page.text)
    paper_template = parsed_mw_text.filter_templates(
        mark_as_paper_template_name)[0]

    if publish_date_param_name in paper_template:
        logger.info(
            f'Page: {paper_page} is already marked with publish date, skipping this paper'
        )
        return

    paper_template.add(publish_date_param_name, publish_date)
    logger.info(
        f'Added publish date: {publish_date} for page: {paper_page.title()}')

    paper_page.text = parsed_mw_text
    if SHOULD_SAVE:
        paper_page.save(
            summary="MaccabiBotAdd publish dates for maariv papers",
            botflag=True)
Example #41
0
    def task(self):
        if self.debug:  # activate for debug purpose
            lemma = "Benutzer:THEbotIT/" + self.bot_name
        else:
            lemma = "Die Gartenlaube"
        page = Page(self.wiki, lemma)
        temp_text = page.text

        alle = self.petscan([])
        fertig = self.petscan(["Fertig"])
        korrigiert = self.petscan(["Korrigiert"])
        unkorrigiert = self.petscan(["Unkorrigiert"])
        articles = self.petscan([], article=True, not_categories=["Die Gartenlaube Hefte"])

        temp_text = self.projektstand(temp_text, alle, fertig, korrigiert, unkorrigiert, articles)
        temp_text = self.alle_seiten(temp_text, alle)
        temp_text = self.korrigierte_seiten(temp_text, korrigiert)
        temp_text = self.fertige_seiten(temp_text, fertig)
        for year in range(1853, 1900):
            temp_text = self.year(year, temp_text)

        page.text = temp_text
        page.save("Ein neuer Datensatz wurde eingefügt.", botflag=True)
        return True
Example #42
0
 def save_if_changed(page: Page, text: str, change_msg: str):
     if text.rstrip() != page.text:
         page.text = text
         page.save(change_msg, botflag=True)
Example #43
0
 def save_if_changed(page: Page, text: str, change_msg: str):
     if text.rstrip() != page.text:
         page.text = text
         page.save(change_msg, botflag=True)
    version_history = page.fullVersionHistory()[::-1]
    size_all_changes = 0
    for idx_rev, revision in enumerate(version_history):
        user = revision.user
        if user == 'Pfaerrich':
             if idx_rev > 0:
                 size_prev = len(version_history[idx_rev-1].text)
             else:
                 size_prev = 0
             size_all_changes += abs(len(version_history[idx_rev].text) - size_prev)
    korrigiert_flag = False
    if size_all_changes > 0:
        for version in page.getVersionHistory():
            if version.user == 'Pfaerrich':
                if re.search('orrigiert', version.comment):
                    korrigiert_flag = True
                    break
    print(size_all_changes, len(page.text), korrigiert_flag)
    if (size_all_changes / len(page.text)) < 0.03 and not korrigiert_flag:
        list_for_pfaerrich.append([page.title(), size_all_changes, len(page.text)])

report_page = Page(wiki, 'Benutzer:THEbotIT/List_for_Pfaerrich')

header = '{|class="wikitable sortable"\n! Lemma\n! Größe\n! geändert von dir'
text = []
for line in list_for_pfaerrich:
    text.append('|-\n|[[{lemma}]]\n|{size}\n|{changes}'.format(lemma=line[0], size=line[2], changes=line[1]))
text = '\n'.join(text)
text = '{header}\n{text}\n|}}'.format(header=header, text=text)
report_page.text = text
report_page.save(botflag=True, summary='blub')
Example #45
0
        if user == 'Pfaerrich':
            if idx_rev > 0:
                size_prev = len(version_history[idx_rev - 1].text)
            else:
                size_prev = 0
            size_all_changes += abs(
                len(version_history[idx_rev].text) - size_prev)
    korrigiert_flag = False
    if size_all_changes > 0:
        for version in page.getVersionHistory():
            if version.user == 'Pfaerrich':
                if re.search('orrigiert', version.comment):
                    korrigiert_flag = True
                    break
    print(size_all_changes, len(page.text), korrigiert_flag)
    if (size_all_changes / len(page.text)) < 0.03 and not korrigiert_flag:
        list_for_pfaerrich.append(
            [page.title(), size_all_changes,
             len(page.text)])

report_page = Page(wiki, 'Benutzer:THEbotIT/List_for_Pfaerrich')

header = '{|class="wikitable sortable"\n! Lemma\n! Größe\n! geändert von dir'
text = []
for line in list_for_pfaerrich:
    text.append('|-\n|[[{lemma}]]\n|{size}\n|{changes}'.format(
        lemma=line[0], size=line[2], changes=line[1]))
text = '\n'.join(text)
text = '{header}\n{text}\n|}}'.format(header=header, text=text)
report_page.text = text
report_page.save(botflag=True, summary='blub')
Example #46
0
# -*- coding: utf-8 -*-
__author__ = 'eso'
import sys
sys.path.append('../../')
import re
from pywikibot import Page, Site
from tools.petscan import PetScan

wiki = Site()

searcher = PetScan()
searcher.add_yes_template('Biel')
lemma_list = searcher.run()

for idx, lemma in enumerate(lemma_list):
    print(idx, len(lemma_list), lemma['title'])
    link_page = Page(wiki, lemma['title'])
    temp_text = link_page.text
    if re.search('\{\{Biel\|', temp_text):
        temp_text = re.sub('\{\{Biel\|1240647\}\}', '{{Bielefeld|1240647}}', temp_text)
        temp_text = re.sub('\{\{Biel\|590504\}\}', '{{Bielefeld|590504}}', temp_text)
        temp_text = re.sub('\{\{Biel\|1732676\}\}', '{{Bielefeld|1732676}}', temp_text)
        temp_text = re.sub('\{\{Biel\|548435\}\}', '{{Bielefeld|548435}}', temp_text)
        temp_text = re.sub('\{\{Biel\|32920\}\}', '{{Bielefeld|32920}}', temp_text)
    if link_page.text != temp_text:
        link_page.text = temp_text
        link_page.save(botflag=True, summary='Biel -> Bielefeld')

Example #47
0
    return presenters_string


if __name__ == '__main__':
    tree = ElementTree.parse(sys.argv[-1])
    out = '<templatestyles src="{}" />\n'.format(CSS_PAGE)
    root = tree.getroot()
    days = root.findall('.//day')
    day_index = 1
    while days:
        day = get_next_day(days)
        days.remove(day)
        day_string = build_day_string(day)
        out += '{{#ifeq:{{{day}}}' + '|{}|'.format(day_index)
        out += '{{#invoke:Program|start|accessibility={{{accessibility}}}|research={{{research}}}|strategy={{{strategy}}}|education={{{education}}}|growth={{{growth}}}|technology={{{technology}}}|partnerships={{{partnerships}}}|technology={{{technology}}}|strategy={{{strategy}}}|health={{{health}}}|partnerships={{{partnerships}}}|multimedia={{{multimedia}}}|glam={{{glam}}}}}'
        events = day.findall('.//event')
        while events:
            event = get_next_event(events)
            events.remove(event)
            out += create_wikitext_item(event)
        out += '{{#invoke:Program|end_}}}}\n'
        day_index += 1
    if '--bot' in sys.argv:
        from pywikibot import Site
        from pywikibot import Page
        page = Page(Site(), PAGE_NAME, PAGE_NAMESPACE)
        page.text = out
        page.save()
    else:
        print(out)