Пример #1
0
def main():
    api = MediaWiki()
    api.login("TAP_Bot", "PASSWORD")
    bot = VitalArticleBot(api)
    if bot.is_allowed:
        bot.run()
    else:
        print("Check the bot's shutoff page!")
    api.logout()
Пример #2
0
    def page_gen_dec(ns):
        def decorator(func):
            # You're lucky I didn't nest this a second time
            real_dec = lambda *pages: (":".join([ns, shit]) for shit in func(*pages))
            return real_dec
        return decorator

    generic_func = lambda *pgs: pgs

    ut = page_gen_dec("User talk")(generic_func)
    t = page_gen_dec("Talk")(generic_func)
    wp = page_gen_dec("Wikipedia")(generic_func)
    wt = page_gen_dec("Wikipedia talk")(generic_func)

    api = MediaWiki(API_URL, config={"retries": 9, "sleep": 9, "maxlag": 9, "throttle": 0.5})
    api.login(*LOGIN_INFO)
    #api.login("throwaway", "aoeui")
    api.set_token("edit")
    shutoff_page = api.page(SHUTOFF)
    victims = itertools.chain((x['title'] for x in api.iterator(list='embeddedin',
                                                                eititle=ARCHIVE_TPL,
                                                                #einamespace=[3,4],
                                                                #eititle="Template:Experimental archiving",
                                                                eilimit=500)),
                              # wp("Administrators' noticeboard/Edit warring",
                              #    "Requests for undeletion",
                              # ),
                              # t("RuneScape",
                              #   "Main Page",
                              # ),
Пример #3
0
                                       for shit in func(*pages))
            return real_dec

        return decorator

    generic_func = lambda *pgs: pgs

    ut = page_gen_dec("User talk")(generic_func)
    t = page_gen_dec("Talk")(generic_func)
    wp = page_gen_dec("Wikipedia")(generic_func)
    wt = page_gen_dec("Wikipedia talk")(generic_func)

    api = MediaWiki(API_URL,
                    config={
                        "retries": 9,
                        "sleep": 9,
                        "maxlag": 9,
                        "throttle": 0.5
                    })
    api.login(*LOGIN_INFO)
    #api.login("throwaway", "aoeui")
    api.set_token("edit")
    shutoff_page = api.page(SHUTOFF)
    victims = itertools.chain(
        (
            x['title'] for x in api.iterator(
                list='embeddedin',
                eititle=ARCHIVE_TPL,
                #einamespace=[3,4],
                #eititle="Template:Experimental archiving",
                eilimit=500)),
Пример #4
0
def main():
    """Set up configuration and start any required scripts or tasks.

    Raises:
        SetupError
    """
    # set available command line arguments
    parser = ArgumentParser(prog='./cresbot.py')
    parser.add_argument('config',
                        help='Set path to config file.')
    parser.add_argument('-t',
                        choices=['all', 'hiscorecounts'],
                        default=[],
                        dest='tasks',
                        help='Run tasks on startup. To run all tasks on startup use `all`. To run specific tasks, add them by name delimited by a space. Allowed task names: `hiscorecounts`.',
                        metavar='task',
                        nargs='*')

    # parse arguments and convert to a dictionary
    args = parser.parse_args()
    args = vars(args)

    # load config from file
    config_path = args.pop('config', 0)

    with open(config_path) as f:
        try:
            config = yaml.load(f)
        except FileNotFoundError as e:
            raise SetupError from e

        # merge args into config
        config.update(args)

    # setup logging
    try:
        log = get_logger(config, 'cresbot')
    except FileNotFoundError as e:
        raise SetupError('Log file could not be found. Please check the directory exists.') from e

    # setup api instance
    api = MediaWiki(config.get('api_url'), config.get('api_config'))

    try:
        logged_in = api.login(config.get('api_username'), config.get('api_password'))
    # @todo catch more specific exception
    #       ApiError?
    except Exception as e:
        raise SetupError('MediaWiki API URL could not be verified. Please check your config file.') from e

    # check login attempt was successful
    if not logged_in:
        raise SetupError('Incorrect password or username in config.')

    # clean up
    api.logout()

    # store in config for convenience
    config.update({'api': api})

    log.info('Setup complete!')

    try:
        tasks.start_tasks(config)
    except Exception as e:
        log.exception('Uncaught exception: %s', e)