Additional IRC commands and bot tasks for EarwigBot https://en.wikipedia.org/wiki/User:EarwigBot
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

afc_dailycats.py 2.6 KiB

11 anos atrás
11 anos atrás
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2009-2014 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. # SOFTWARE.
  20. from datetime import datetime, timedelta
  21. from earwigbot.tasks import Task
  22. class AfCDailyCats(Task):
  23. """A task to create daily categories for [[WP:AFC]]."""
  24. name = "afc_dailycats"
  25. number = 3
  26. def setup(self):
  27. cfg = self.config.tasks.get(self.name, {})
  28. self.prefix = cfg.get("prefix", "Category:AfC submissions by date/")
  29. self.content = cfg.get("content", "{{AfC submission category header}}")
  30. default_summary = (
  31. "Creating {0} category page for [[WP:AFC|Articles for creation]]."
  32. )
  33. self.summary = self.make_summary(cfg.get("summary", default_summary))
  34. def run(self, **kwargs):
  35. if self.shutoff_enabled():
  36. return
  37. self.site = self.bot.wiki.get_site()
  38. self.make_cats()
  39. self.make_cats(1)
  40. self.make_cats(2)
  41. self.make_cats(3)
  42. def make_cats(self, days=0):
  43. dt = datetime.now() + timedelta(days)
  44. self.make_cat(dt.strftime("%d %B %Y"), "daily")
  45. if dt.day == 1:
  46. self.make_cat(dt.strftime("%B %Y"), "monthly")
  47. if dt.month == 1:
  48. self.make_cat(dt.strftime("%Y"), "yearly")
  49. def make_cat(self, suffix, word):
  50. page = self.site.get_page(self.prefix + suffix)
  51. if page.exists == page.PAGE_MISSING:
  52. page.edit(self.content, self.summary.format(word))
  53. self.logger.info(f"Creating [[{page.title}]]")
  54. else:
  55. self.logger.debug(f"Skipping [[{page.title}]], exists")