Index: trunk/tools/fancy-uploader/fancy-uploader.py |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | |
41 | 41 | title = u'%s - %s - %s.%s' % (base_title, metadata['project'], metadata['id'], metadata['extension']) |
42 | 42 | |
43 | | - return cleanup_title(title) |
| 43 | + return self.cleanup_title(title) |
44 | 44 | |
45 | 45 | def cleanup_title(self, title): |
46 | 46 | ''' |
— | — | @@ -50,23 +50,24 @@ |
51 | 51 | |
52 | 52 | def convert_dict_to_wikitext(self, template, dict): |
53 | 53 | # TODO curly brace escaping |
54 | | - return '{{subst:%s|%s|subst=subst:}}' % (template, '|'.join('%s=%s' for i in dict.iteritems())) |
| 54 | + return '{{subst:%s|%s|subst=subst:}}' % (template, '|'.join('%s=%s' % i for i in dict.iteritems())) |
55 | 55 | |
56 | 56 | def upload(self, username, password, file, filename, wikitext): |
57 | | - site = mwclient.Site('commons.wikimedia.org') |
| 57 | + site = mwclient.Site('test.wikipedia.org') |
58 | 58 | site.login(username, password) |
59 | | - return site.upload(file, filename, wikitext) |
| 59 | + return site.upload(file, filename, wikitext, ignore = True) |
60 | 60 | |
61 | 61 | def run(self, data, filename): |
62 | | - title = self.construct_title() |
| 62 | + title = self.construct_title(data['metadata']) |
63 | 63 | wikitext = self.convert_dict_to_wikitext(data['body_template'], |
64 | 64 | data['metadata']) |
65 | 65 | result = self.upload(data['username'], data['password'], |
66 | 66 | open(filename, 'rb'), title, wikitext) |
| 67 | + return result |
67 | 68 | |
68 | 69 | if __name__ == '__main__': |
69 | 70 | uploader = FancyUploader() |
70 | 71 | data = json.load(open(sys.argv[1], 'rb')) |
71 | 72 | result = uploader.run(data, sys.argv[2]) |
72 | | - json.dump(sys.stdout, result) |
| 73 | + json.dump(result, sys.stdout) |
73 | 74 | |