Exemplo n.º 1
0
def main(*args):
    site = pywikibot.Site()
    fetcher = CategoryFetcher(site)
    checker = TemplateChecker()
    checker.load_config("config/templates.json")
    checker_bot = CheckerBot(checker, site)
    all_categories = fetcher.get_categories()
    callbacks = ArticleIteratorCallbacks(
        category_callback=checker_bot.cb_store_category_result,
        article_callback=checker_bot.cb_check_article,
        logging_callback=pywikibot.log,
    )
    article_iterator = ArticleIterator(callbacks, categories=all_categories)
    parser = ArticleIteratorArgumentParser(article_iterator, fetcher)
    for argument in pywikibot.handle_args(list(args)):
        if parser.check_argument(argument):
            continue
        elif argument.find("-outputpage:") == 0:
            checker_bot.outputpage = argument[12:]
        elif argument.find("-exclude-articles:") == 0:
            page = pywikibot.Page(site, argument[18:])
            article_iterator.excluded_articles = load_excluded_articles_from_wiki(page)
    article_iterator.iterate_categories()

    if article_iterator.categories != all_categories:   # Don't update summary page if only single categories were crawled
        return
    summary = checker_bot.generate_summary_page()
    if checker_bot.outputpage:
        checker_bot.save_wikipage(summary, checker_bot.outputpage + u"/Zusammenfassung")
    else:
        pywikibot.output(u"Zusammenfassung")
        pywikibot.output(u"===============")
        pywikibot.output(summary)
        pywikibot.output(checker_bot.generate_config_table())
Exemplo n.º 2
0
def main(*args):
    wikipedia_site = pywikibot.Site()  # Use the site configured in params/user-config
    commons_site = pywikibot.Site("commons", "commons")
    checker = TemplateChecker()
    checker.load_config("config/templates.json")
    commons_bot = CommonsBot(wikipedia_site, checker)
    callbacks = ArticleIteratorCallbacks(
        logging_callback=pywikibot.log,
        article_callback=commons_bot.cb_check_article
    )
    article_iterator = ArticleIterator(callbacks)
    article_iterator.log_every_n = 1
    parser = ArticleIteratorArgumentParser(article_iterator, None)
    run_cmd = commons_bot.run_continuously
    category_name = u"Images from Wiki Loves Monuments 2015 in Germany"
    start_time = first_day_of_month()
    for argument in pywikibot.handle_args(args):
        if argument.find("-category:") == 0:
            category_name = argument[10:]
            continue
        elif parser.check_argument(argument):
            continue
        elif argument.find("-start-at:") == 0:
            start_time_iso = argument[10:] + "T0:00:00Z"
            start_time = pywikibot.Timestamp.fromISOformat(start_time_iso)
        elif argument.find("-sleep-seconds:") == 0 and int(argument[15:]) > 0:
            commons_bot.sleep_seconds = int(argument[15:])
        elif argument == "-once":
            run_cmd = commons_bot.run_once
        elif argument == "-local-media":
            commons_site = wikipedia_site
    category = pywikibot.Category(commons_site, category_name)
    run_cmd(article_iterator, start_time, category)
 def test_multiple_categories_are_supported(self):
     article_iterator = Mock()
     category_fetcher = Mock()
     category = Mock()
     category_fetcher.get_categories_filtered_by_name.return_value = [category]
     parser = ArticleIteratorArgumentParser(article_iterator, category_fetcher)
     self.assertTrue(parser.check_argument(u"-category:Baudenkmäler_in_Sachsen,Baudenkmäler in Bayern"))
     category_fetcher.get_categories_filtered_by_name.assert_called_once_with([u"Kategorie:Baudenkmäler in Sachsen", u"Kategorie:Baudenkmäler in Bayern"])
 def test_category_sets_pywikibot_category(self):
     article_iterator = Mock()
     category_fetcher = Mock()
     category = Mock()
     category_fetcher.get_categories_filtered_by_name.return_value = [category]
     parser = ArticleIteratorArgumentParser(article_iterator, category_fetcher)
     self.assertTrue(parser.check_argument(u"-category:Baudenkmäler in Sachsen"))
     self.assertEqual(article_iterator.categories, [category])
 def test_parser_returns_false_when_no_valid_argument_is_found(self):
     parser = ArticleIteratorArgumentParser(Mock(), Mock())
     self.assertFalse(parser.check_argument("-foo"))
 def test_category_limit_is_set(self):
     article_iterator = Mock()
     parser = ArticleIteratorArgumentParser(article_iterator, Mock())
     self.assertTrue(parser.check_argument("-limit-per-category:10"))
     self.assertEqual(article_iterator.articles_per_category_limit, 10)
 def test_limit_is_set(self):
     article_iterator = Mock()
     parser = ArticleIteratorArgumentParser(article_iterator, Mock())
     self.assertTrue(parser.check_argument("-limit:5"))
     self.assertEqual(article_iterator.limit, 5)