Ejemplo n.º 1
0
NAME = "Delete unreferenced pages"
DESCRIPTION = "Deletes pages that are not referenced in other places. PLEASE USE ONLY IN FILE NAMESPACES!"


class DeleteUnreferencedPages(JobWithQuery):

    def __init__(self):
        super().__init__()

    def before_process(self):
        self.logger.warning(self.lang.t("scripts.unreferenced.warning"))
        cont = input(self.lang.t("scripts.unreferenced.confirm"))
        if cont != self.lang.t("scripts.unreferenced.confirmkey"):
            import sys
            sys.exit(1)

    def process(self, article):
        result = self.client.api("query", list="imageusage", iutitle=article)
        if len(result["query"]["imageusage"]) == 0:
            token = self.client.api("query", meta="tokens", type="csrf")["query"]["tokens"]["csrftoken"]
            self.client.api("delete", title=article, reason=self.lang.t("scripts.unreferenced.reason"), token=token)

    @property
    def querybuilder_title(self):
        return self.lang.t("scripts.unreferenced.name")


# Don't delete this line or your script won't start
BotMain(DESCRIPTION).start(DeleteUnreferencedPages())
Ejemplo n.º 2
0
            "selectedDestinationId":
            "Save as PDF",
            "version":
            2
        }
        prefs = {
            'printing.print_preview_sticky_settings.appState':
            json.dumps(settings),
            'savefile.default_directory': 'c:\\inciclopedia'
        }
        chrome_options.add_experimental_option('prefs', prefs)
        chrome_options.add_argument('--kiosk-printing')
        self.driver = webdriver.Chrome(chrome_options=chrome_options,
                                       executable_path=CHROMEDRIVER_PATH)

    def process(self, article):
        # your code for each article goes here
        self.driver.get("https://inciclopedia.org/wiki/" + quote(article))
        self.driver.execute_script('window.print();')

    @property
    def querybuilder_title(self):
        # Ideally you would add in your JSON the translations and use this:
        # return self.lang.t("scripts.yourscriptname.name")
        # If you feel lazy, hardcode the value
        return "Print article"


# Don't delete this line or your script won't start
BotMain(DESCRIPTION).start(TemplateWithQuery())
Ejemplo n.º 3
0
from common.botmain import BotMain
from common.job import Job

DESCRIPTION = "Describe your task here"


# Change the class name to your job name, change it also in last line
class Template(Job):
    def task(self):
        # Your code goes here
        pass


# Don't delete this line or your script won't start
BotMain(DESCRIPTION).start(Template())
Ejemplo n.º 4
0
NAME = "Delete page"
DESCRIPTION = "This script deletes all the pages from the given query with the given protection level"
REASON = "Juzgado en VPB"


class MassDelete(JobWithQuery):
    def __init__(self):
        super().__init__()

    def before_process(self):
        self.logger.warning(self.lang.t("scripts.massdelete.warning"))
        cont = input(self.lang.t("scripts.massdelete.confirm"))
        if cont != self.lang.t("scripts.massdelete.confirmkey"):
            import sys
            sys.exit(1)

    def process(self, page_name):
        token = self.client.api("query", meta="tokens",
                                type="csrf")["query"]["tokens"]["csrftoken"]
        self.client.api("delete", title=page_name, reason=REASON, token=token)
        self.logger.info(
            self.lang.t("common.processed").format(name=page_name))

    @property
    def querybuilder_title(self):
        return self.lang.t("scripts.massdelete.name")


BotMain(DESCRIPTION).start(MassDelete())
Ejemplo n.º 5
0
class CleanupDoubleRedirects(JobWithQuery):

    def __init__(self):
        super().__init__()

    def process(self, article):
        page = Page(self.client, article)
        if not page.redirect:
            return
        self.logger.info(self.lang.t("scripts.cleanupdoubleredirects.processing").format(name=article))
        redirection_chain = []
        while page.redirect:
            if page.name in redirection_chain:
                self.logger.warning(self.lang.t("cleanupdoubleredirects.circular_reference").format(name=article))
                return
            redirection_chain.append(page.name)
            page = Page(self.client, page.redirects_to())
        if len(redirection_chain) > 1:
            for redirect in redirection_chain[:-1]:
                self.logger.info(self.lang.t("resolving").format(redirect=redirect, target=page.name))
                redir = Page(self.client, redirect)
                redir.edit("#REDIRECT [[" + page.name + "]]", self.lang.t("scripts.cleanupdoubleredirects.reason")
                           .format(target=page.name))

    @property
    def querybuilder_title(self):
        return self.lang.t("scripts.cleanupdoubleredirects.name")


BotMain(DESCRIPTION).start(CleanupDoubleRedirects())
Ejemplo n.º 6
0
class ArticleList(JobWithQuery):
    def __init__(self):
        super().__init__()
        self.file = None
        self.fname = None

    @inject.param('lang', Lang)
    def before_process(self, lang: Lang = None):
        self.fname = input(lang.t("scripts.articlelist.choose_path"))
        self.file = open(self.fname, "w", encoding="utf-8")

    @property
    @inject.param('lang', Lang)
    def querybuilder_title(self, lang: Lang = None):
        return lang.t("scripts.articlelist.name")

    def process(self, article):
        self.file.write(article + "\n")

    @inject.param('lang', Lang)
    def after_process(self, lang: Lang = None):
        print(
            lang.t("scripts.articlelist.task_completed").format(
                fname=self.fname))
        self.file.close()


# Don't delete this line or your script won't start
BotMain(DESCRIPTION).start(ArticleList())
Ejemplo n.º 7
0
from mwclient import LoginError

from common.botmain import BotMain
from common.interwiki.interwikijob import InterwikiJob
from common.jobwithquery import JobWithQuery

DESCRIPTION = "This script remaps all interwikis from the given query"


class InterwikiRemapper(InterwikiJob, JobWithQuery):
    @property
    def querybuilder_title(self):
        return self.lang.t("interwiki.querybuilder_title")

    def process(self, article):
        try:
            self.client.login(self.client.username, self.password)
        except LoginError:
            pass
        try:
            self.remap_interwikis(article)
        except Exception as e:
            self.logger.error(str(e))

    def __init__(self):
        super().__init__()


BotMain(DESCRIPTION).start(InterwikiRemapper())
Ejemplo n.º 8
0
    @property
    def querybuilder_title(self):
        return self.lang.t("scripts.recategorize.name")

    def validate_query(self, query, browser):
        if not query or len(query) == 0:
            return False
        if query.lower() == 'n':
            webbrowser.open(browser)
            return False
        for subquery in query.split(','):
            if subquery.strip()[0] not in ('+', '-', '%'):
                print(self.lang.t("scripts.recategorize.category_validation_error"))
                return False
        return True

    def ask_query(self, browser=None):
        print(self.lang.t("scripts.recategorize.category_query_help"))
        print(self.lang.t("scripts.recategorize.category_query_example"))
        if browser:
            print(self.lang.t("scripts.recategorize.category_query_browser"))
        self.query = None
        while not self.validate_query(self.query, browser):
            self.query = input(self.lang.t("common.type_query"))
            if self.query == "":
                return


BotMain(DESCRIPTION).start(Recategorize())
Ejemplo n.º 9
0
from common.botmain import BotMain
from common.jobwithquery import JobWithQuery

NAME = "Protect page"
DESCRIPTION = "This script protects all the pages from the given query with the given protection level"
PRLEVEL = "edit=sysop|move=sysop"
REASON = "Bot's fault"


class ProtectPage(JobWithQuery):
    def __init__(self):
        super().__init__()

    def process(self, page_name):
        token = self.client.api("query", meta="tokens",
                                type="csrf")["query"]["tokens"]["csrftoken"]
        self.client.api("protect",
                        title=page_name,
                        protections=PRLEVEL,
                        reason=REASON,
                        token=token)

    @property
    def querybuilder_title(self):
        return self.lang.t("scripts.protectpage.name")


BotMain(DESCRIPTION).start(ProtectPage())
Ejemplo n.º 10
0
    def process(self, article):
        page = Page(self.client, article)
        wikitext = page.text()
        matches = re.search(
            r"\[\[((?:[^\]|$]+)(?=.png|.jpg|.jpeg|.gif|.svg).png|.jpg|.jpeg|.gif|svg)(?:|[^\]$]+)\]\]",
            wikitext)
        if matches:
            for match in matches.groups():
                self.file.write(match + "\n")

    def before_process(self):
        self.fname = input(self.lang.t("scripts.articlelist.choose_path"))
        self.file = open(self.fname, "w", encoding="utf-8")

    def after_process(self):
        print(
            self.lang.t("scripts.articlelist.task_completed").format(
                fname=self.fname))
        self.file.close()

    @property
    def querybuilder_title(self):
        # Ideally you would add in your JSON the translations and use this:
        # return self.lang.t("scripts.yourscriptname.name")
        # If you feel lazy, hardcode the value
        return "List Pictures"


# Don't delete this line or your script won't start
BotMain(DESCRIPTION).start(ListPictures())
Ejemplo n.º 11
0
from common.botmain import BotMain
from common.interwiki.interwikijob import InterwikiJob

NAME = "Interwiki Daily Job"
DESCRIPTION = "This script remaps automatically the interwikis of the articles created in the last day"


class InterwikiDailyJob(InterwikiJob):
    def __init__(self):
        super().__init__()

    def task(self):
        from datetime import datetime, timedelta
        end = datetime.now()
        # three hours margin so we don't miss interwikis between cron jobs
        start = end - timedelta(days=1, hours=3)
        results = self.client.recentchanges(dir="older",
                                            namespace='0',
                                            type='new',
                                            limit=500)
        for article in results:
            if article["timestamp"] > start.timetuple():
                if article["ns"] == 0:
                    self.remap_interwikis(article["title"])


# Don't delete this line or your script won't start
BotMain(DESCRIPTION).start(InterwikiDailyJob())
Ejemplo n.º 12
0
from mwclient.page import Page

from common.botmain import BotMain
from common.jobwithquery import JobWithQuery

NAME = "Purge"
DESCRIPTION = "This script purges the given articles"


class Purge(JobWithQuery):

    @property
    def querybuilder_title(self):
        return self.lang.t("scripts.purge.name")

    def __init__(self):
        super().__init__()

    def process(self, article):
        page = Page(self.client, article)
        page.purge()
        self.logger.info(self.lang.t("common.processed").format(name=article))


BotMain(DESCRIPTION).start(Purge())