Permalink
Browse files

[defcon] Stop unnecessary edits; update info param

The bot will now read the existing RPM value from Template:Vandalism information and only edit when the one it has just calculated is different. Furthermore, the bot will now specify the RPM (to two decimal places) in the `info` parameter of Template:Vandalism information.
  • Loading branch information...
enterprisey committed Jan 21, 2016
1 parent 146d7ae commit 82d971706d8071098747b401167f7f93c86d925a
Showing with 13 additions and 11 deletions.
  1. +12 −10 defcon/defcon.py
  2. +1 −1 defcon/template.txt
View
@@ -19,15 +19,17 @@
rpm = float(num_reverts) / 30
template_page = pywikibot.Page(site, TEMPLATE_NAME)
try:
template = open(TEMPLATE_PATH)
except IOError as e:
print(e)
else:
current_rpm_match = re.search("WikiDefcon/levels\|(\d+)", template_page.get())
if (not current_rpm_match) or (current_defcon_match.group(1) != int(rpm)):
try:
template_page.text = template.read() % int(rpm)
except Exception as e:
template = open(TEMPLATE_PATH)
except IOError as e:
print(e)
finally:
template.close()
template_page.save(COMMENT % int(rpm))
else:
try:
template_page.text = template.read() % (int(rpm), rpm)
template_page.save(COMMENT % int(rpm))
except Exception as e:
print(e)
finally:
template.close()
View
@@ -1,7 +1,7 @@
{{{{#if:{{{style|}}}|wdefcon/styles/{{{style}}}|{{{prefix|User:Zsinj/}}}Wdefcon}}
|level = {{WikiDefcon/levels|%d}}
|sign = ~~~~~
|info = RPM stats according to [[User:APersonBot|APersonBot]]
|info = %.2f RPM according to [[User:APersonBot|APersonBot]]
|align = {{{align|}}}
|noinfo = {{{noinfo|}}}
|type = {{{type|}}}

0 comments on commit 82d9717

Please sign in to comment.