Skip to content

Commit

Permalink
[defcon] Stop unnecessary edits; update info param
Browse files Browse the repository at this point in the history
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 82d9717
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions defcon/defcon.py
Expand Up @@ -19,15 +19,17 @@
rpm = float(num_reverts) / 30 rpm = float(num_reverts) / 30


template_page = pywikibot.Page(site, TEMPLATE_NAME) template_page = pywikibot.Page(site, TEMPLATE_NAME)
try: current_rpm_match = re.search("WikiDefcon/levels\|(\d+)", template_page.get())
template = open(TEMPLATE_PATH) if (not current_rpm_match) or (current_defcon_match.group(1) != int(rpm)):
except IOError as e:
print(e)
else:
try: try:
template_page.text = template.read() % int(rpm) template = open(TEMPLATE_PATH)
except Exception as e: except IOError as e:
print(e) print(e)
finally: else:
template.close() try:
template_page.save(COMMENT % int(rpm)) template_page.text = template.read() % (int(rpm), rpm)
template_page.save(COMMENT % int(rpm))
except Exception as e:
print(e)
finally:
template.close()
2 changes: 1 addition & 1 deletion defcon/template.txt
@@ -1,7 +1,7 @@
{{{{#if:{{{style|}}}|wdefcon/styles/{{{style}}}|{{{prefix|User:Zsinj/}}}Wdefcon}} {{{{#if:{{{style|}}}|wdefcon/styles/{{{style}}}|{{{prefix|User:Zsinj/}}}Wdefcon}}
|level = {{WikiDefcon/levels|%d}} |level = {{WikiDefcon/levels|%d}}
|sign = ~~~~~ |sign = ~~~~~
|info = RPM stats according to [[User:APersonBot|APersonBot]] |info = %.2f RPM according to [[User:APersonBot|APersonBot]]
|align = {{{align|}}} |align = {{{align|}}}
|noinfo = {{{noinfo|}}} |noinfo = {{{noinfo|}}}
|type = {{{type|}}} |type = {{{type|}}}
Expand Down

0 comments on commit 82d9717

Please sign in to comment.