User:Opabinia robotus/upload taxa.py


 * 1) ! /usr/bin/python


 * 1) Very very simple pywikipedia script for uploading taxonomy stubs

import wikipedia import sys import os import time

if len(sys.argv) < 2: print "Please give at least one file to upload." sys.exit(1)
 * 1) die if no files provided


 * 1) pywikipedia setup

en = wikipedia.getSite
 * 1) we're on the english wikipedia

filelist = sys.argv filelist.pop(0)
 * 1) get rid of first element

for taxofile in filelist: if os.path.exists(taxofile) == 0: print "%s does not exist." % (taxofile) continue container = open(taxofile,'r') articlecontent = container.read container.close
 * 1) upload one file at a time, 30s apart

if len(articlecontent) == 0: print "Sorry, empty file." continue else: # assume for now that page title = "User:Opabinia_robotus/filename" articletitle = "User:Opabinia_robotus/" + taxofile articlepage = wikipedia.Page(en,articletitle) # check for current content # if the page exists, don't upload if articlepage.exists: print "This page already exists." continue # create edit summary editsummary = "Creating page " + articletitle # upload print articletitle articlepage.put(articlecontent,editsummary) # wait 30s before next upload time.sleep(30)