r80253 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80252‎ | r80253 | r80254 >
Date:11:39, 14 January 2011
Author:btongminh
Status:deferred
Tags:
Comment:
First quick hackup of the fancy uploader
Modified paths:
  • /trunk/tools/fancy-uploader (modified) (history)
  • /trunk/tools/fancy-uploader/fancy-uploader.py (modified) (history)

Diff [purge]

Index: trunk/tools/fancy-uploader/fancy-uploader.py
@@ -1,13 +1,50 @@
22 #!/usr/bin/python
33
 4+"""
 5+Copyright 2011 - Bryan Tong Minh
 6+Licensed under the terms of the MIT license
 7+"""
 8+
 9+"""
 10+TODO:
 11+ - Dupe detection
 12+
 13+"""
 14+import sys
 15+
 16+import mwclient
 17+try:
 18+ import json
 19+except ImportError:
 20+ import simplejson as json
 21+
422 class FancyUploader(object):
523
624 def __init__(self):
725 pass
826
9 - def convert_json_to_wikitext(self, json):
 27+ def construct_title(self):
1028 pass
1129
12 - def upload(self, data):
13 - pass
 30+ def convert_dict_to_wikitext(self, template, dict):
 31+ # TODO curly brace escaping
 32+ return '{{%s|%s}}' % (template, '|'.join('%s=%s' for i in dict.iteritems()))
1433
 34+ def upload(self, username, password, file, filename, wikitext):
 35+ site = mwclient.Site('commons.wikimedia.org')
 36+ site.login(username, password)
 37+ return site.upload(file, filename, wikitext)
 38+
 39+ def run(self, data, filename):
 40+ title = self.construct_title()
 41+ wikitext = self.convert_dict_to_wikitext(data['body_template'],
 42+ data['metadata'])
 43+ result = self.upload(data['username'], data['password'],
 44+ open(filename, 'rb'), title, wikitext)
 45+
 46+if __name__ == '__main__':
 47+ uploader = FancyUploader()
 48+ data = json.load(open(sys.argv[1], 'rb'))
 49+ result = uploader.run(data, sys.argv[2])
 50+ json.dump(sys.stdout, result)
 51+
Property changes on: trunk/tools/fancy-uploader/fancy-uploader.py
___________________________________________________________________
Added: svn:executable
1552 + *
Property changes on: trunk/tools/fancy-uploader
___________________________________________________________________
Added: svn:externals
1653 + mwclient https://mwclient.svn.sourceforge.net/svnroot/mwclient/trunk/mwclient/

Status & tagging log