Additional IRC commands and bot tasks for EarwigBot https://en.wikipedia.org/wiki/User:EarwigBot
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

65 行
2.6 KiB

  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")