| @@ -21,6 +21,7 @@ | |||||
| # SOFTWARE. | # SOFTWARE. | ||||
| from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
| from time import sleep | |||||
| from earwigbot.tasks import Task | from earwigbot.tasks import Task | ||||
| from earwigbot.wiki import constants | from earwigbot.wiki import constants | ||||
| @@ -52,16 +53,18 @@ class InfoboxStation(Task): | |||||
| ), | ), | ||||
| } | } | ||||
| self._replacement = "{{Infobox station}}" | self._replacement = "{{Infobox station}}" | ||||
| self._sleep_time = 6 | |||||
| self.summary = self.make_summary( | self.summary = self.make_summary( | ||||
| "Replacing {source} with {dest} per [[{discussion}|TfD]].") | "Replacing {source} with {dest} per [[{discussion}|TfD]].") | ||||
| def run(self, **kwargs): | def run(self, **kwargs): | ||||
| limit = int(kwargs.get("limit"), 0) | |||||
| for name, args in self._targets.items(): | for name, args in self._targets.items(): | ||||
| if self.shutoff_enabled(): | if self.shutoff_enabled(): | ||||
| return | return | ||||
| self._replace(name, args) | |||||
| self._replace(name, args, limit) | |||||
| def _replace(self, name, args): | |||||
| def _replace(self, name, args, limit=0): | |||||
| """ | """ | ||||
| Replace a template in all pages that transclude it. | Replace a template in all pages that transclude it. | ||||
| """ | """ | ||||
| @@ -69,12 +72,18 @@ class InfoboxStation(Task): | |||||
| count = 0 | count = 0 | ||||
| for title in self._get_transclusions(args[0][0]): | for title in self._get_transclusions(args[0][0]): | ||||
| if limit > 0 and count >= limit: | |||||
| logmsg = "Reached limit of {0} edits for {1} infoboxes" | |||||
| self.logger.info(logmsg.format(limit, name)) | |||||
| return | |||||
| count += 1 | count += 1 | ||||
| if count % 10 == 0 and self.shutoff_enabled(): | |||||
| if count % 5 == 0 and self.shutoff_enabled(): | |||||
| return | return | ||||
| page = self.site.get_page(title) | page = self.site.get_page(title) | ||||
| self._process_page(page, args) | self._process_page(page, args) | ||||
| self.logger.info("All {0} infoboxes updated".format(name)) | |||||
| def _process_page(self, page, args): | def _process_page(self, page, args): | ||||
| """ | """ | ||||
| Process a single page to replace a template. | Process a single page to replace a template. | ||||
| @@ -102,6 +111,7 @@ class InfoboxStation(Task): | |||||
| source="{{" + args[0][0] + "}}", dest=self._replacement, | source="{{" + args[0][0] + "}}", dest=self._replacement, | ||||
| discussion=args[3]) | discussion=args[3]) | ||||
| page.edit(unicode(code), summary, minor=True) | page.edit(unicode(code), summary, minor=True) | ||||
| sleep(self._sleep_time) | |||||
| def _add_cats(self, code, cats): | def _add_cats(self, code, cats): | ||||
| """Add category data (*cats*) to wikicode.""" | """Add category data (*cats*) to wikicode.""" | ||||