Skip to content

Commit

Permalink
+ oa-put upload and create page in one step
Browse files Browse the repository at this point in the history
  • Loading branch information
erlehmann committed Sep 23, 2012
1 parent c252b8d commit d0bc332
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions oa-put
Expand Up @@ -127,17 +127,18 @@ if action == 'upload-media':
elif major_category is not None: elif major_category is not None:
wiki_filename = major_category.replace(' ', '-') + '-' + wiki_filename 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 = wikitools.wikifile.File(wiki=wiki, title=wiki_filename)
wiki_file.upload( wiki_file.upload(
fileobj = open(media_refined_path, 'r'), 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]]' 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" % ( stderr.write("“%s” uploaded to <%s>.\n" % (
media_refined_path.encode('utf-8'), media_refined_path.encode('utf-8'),
config.api_url.encode('utf-8') config.api_url.encode('utf-8')
Expand Down
3 changes: 2 additions & 1 deletion wikitools/wikifile.py
Expand Up @@ -194,7 +194,7 @@ def download(self, width=False, height=False, location=False):
f.close() f.close()
return location 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 """Upload a file, requires the "poster" module
fileobj - A file object opened for reading fileobj - A file object opened for reading
Expand All @@ -214,6 +214,7 @@ def upload(self, fileobj=None, comment='', url=None, ignorewarnings=False, watch
params = {'action':'upload', params = {'action':'upload',
'comment':comment, 'comment':comment,
'filename':self.unprefixedtitle, 'filename':self.unprefixedtitle,
'text':text,
'token':self.getToken('edit') # There's no specific "upload" token 'token':self.getToken('edit') # There's no specific "upload" token
} }
if url: if url:
Expand Down

0 comments on commit d0bc332

Please sign in to comment.