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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion defcon/template.txt
Original file line number Diff line number Diff line change
@@ -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|}}}
Expand Down

0 comments on commit 82d9717

Please sign in to comment.