Permalink
Browse files

+ oa-put upload and create page in one step

  • Loading branch information...
erlehmann committed Sep 23, 2012
1 parent c252b8d commit d0bc332077133a2d9c065bf3fd6ceb975ed705f2
Showing with 9 additions and 7 deletions.
  1. +7 −6 oa-put
  2. +2 −1 wikitools/wikifile.py
View
13 oa-put
@@ -127,17 +127,18 @@ if action == 'upload-media':
elif major_category is not None:
wiki_filename = major_category.replace(' ', '-') + '-' + wiki_filename
page_template = template.page(article_doi, article_pmid, \
article_pmcid, authors, article_title, journal_title, \
date, article_url, license_url, rights_holder, label, \
caption, categories)
wiki_file = wikitools.wikifile.File(wiki=wiki, title=wiki_filename)
wiki_file.upload(
fileobj = open(media_refined_path, 'r'),
text=page_template.encode('utf-8'),
comment = 'Uploaded with the Open Access Media Importer. (test edit) [[Commons:Bots/Requests#Open_Access_Media_Importer_Bot_.28talk.C2.A0.C2.B7_contribs.29|botrequest]]'
)
page = wikitools.Page(wiki, "File:" + wiki_filename, followRedir=True)
page_template = template.page(article_doi, article_pmid, \
article_pmcid, authors, article_title, journal_title, \
date, article_url, license_url, rights_holder, label, \
caption, categories)
page.edit(text=page_template.encode('utf-8'))
stderr.write("%s” uploaded to <%s>.\n" % (
media_refined_path.encode('utf-8'),
config.api_url.encode('utf-8')
View
@@ -194,7 +194,7 @@ def download(self, width=False, height=False, location=False):
f.close()
return location
def upload(self, fileobj=None, comment='', url=None, ignorewarnings=False, watch=False):
def upload(self, fileobj=None, comment='', text='', url=None, ignorewarnings=False, watch=False):
"""Upload a file, requires the "poster" module
fileobj - A file object opened for reading
@@ -214,6 +214,7 @@ def upload(self, fileobj=None, comment='', url=None, ignorewarnings=False, watch
params = {'action':'upload',
'comment':comment,
'filename':self.unprefixedtitle,
'text':text,
'token':self.getToken('edit') # There's no specific "upload" token
}
if url:

0 comments on commit d0bc332

Please sign in to comment.