Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #9 from weisslj/cancel_edits

Add cancel_edits.py script
  • Loading branch information...
commit 26165c19d65b8fa0977e329b1ff599e1cbc5d356 2 parents 8937ea0 + 97a944e
@weisslj authored
Showing with 44 additions and 0 deletions.
  1. +36 −0 cancel_edits.py
  2. +8 −0 editing.py
View
36 cancel_edits.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+import re
+import sys
+import locale
+from editing import MusicBrainzClient
+from mbbot.utils.pidfile import PIDFile
+from utils import out
+import config as cfg
+
+def main(args):
+ if not args:
+ out('Usage: cancel_edits.py <edit_number edit_note>...\n')
+ out('Example: cancel_edits.py "Edit #123 my mistake"')
+ out(' cancel_edits.py 123 124 125')
+ return
+
+ edits = []
+ for arg in args:
+ if not isinstance(arg, unicode):
+ arg = unicode(arg, locale.getpreferredencoding())
+ m = re.match(ur'(?:[Ee]dit )?#?([0-9]+) ?(.*)$', arg)
+ if not m:
+ out('invalid edit number "%s", aborting!' % arg)
+ return
+ edit_nr = str(m.group(1))
+ edit_note = m.group(2).lstrip()
+ edits.append((edit_nr, edit_note))
+
+ mb = MusicBrainzClient(cfg.MB_USERNAME, cfg.MB_PASSWORD, cfg.MB_SITE)
+ for edit_nr, edit_note in edits:
+ out(u'Cancel edit #%s: %s' % (edit_nr, edit_note if edit_note else u'<no edit note>'))
+ mb.cancel_edit(str(edit_nr), edit_note)
+
+if __name__ == '__main__':
+ with PIDFile('/tmp/mbbot_cancel_edits.pid'):
+ main(sys.argv[1:])
View
8 editing.py
@@ -343,3 +343,11 @@ def add_edit_note(self, identify, edit_note):
self.b['enter-vote.vote.%d.edit_note' % i] = edit_note.encode('utf8')
break
self.b.submit()
+
+ def cancel_edit(self, edit_nr, edit_note=u''):
+ self.b.open(self.url("/edit/%s/cancel" % (edit_nr,)))
+ page = self.b.response().read()
+ self.b.select_form(predicate=lambda f: f.method == "POST" and "/cancel" in f.action)
+ if edit_note:
+ self.b['confirm.edit_note'] = edit_note.encode('utf8')
+ self.b.submit()
Please sign in to comment.
Something went wrong with that request. Please try again.