User:Kroocsiogsi/Bulk uploads with PyWikipediaBot

Installation

 * 1) Create a new Dota 2 Wiki user, and ask a Dota 2 Wiki administrator to give it bot privileges.
 * 2) Install Python 2.6.x (2.6.5 at the time of this guide). (Python 3 is not compatible with PyWikipediaBot, and I have Unicode problems with with 2.7.x.)
 * 3) Download and uncompress PyWikipediaBot.
 * 4) Create dota2wiki_family.py in "pywikipedia/families".
 * 5) Create user-config.py in "pywikipedia". Replace "KrooBot" with the name of your bot.
 * 6) Open a command prompt at the pywikipedia directory and login with "python login.py". You will have to supply the correct password. Once logged in, your bot will usually stay logged in permanently.
 * 7)  Create bulkUpload.py and bulkUpload_conf.py in "pywikipedia".

Use

 * 1) Modify bulkUpload_conf.py with the appropriate uploadText (such as categorization) and appropriate filename modifications (if necessary).
 * 2) Copy the directory containing the files you want to upload to the pywikipedia directory. (Right now, bulkUpload.py is customized to upload mp3s only, but I'm sure you can figure out how to change that.)
 * 3) Run "bulkUpload.py directory" from the command line.

dota2wiki_family.py
""" This family file was auto-generated by $Id: generate_family_file.py 9734 2011-11-09 22:17:11Z valhallasw $ Configuration parameters: url = http://www.dota2wiki.com/wiki/Dota_2_Wiki  name = Dota2Wiki
 * 1) -*- coding: utf-8 -*-

Please do not commit this to the SVN repository! """

import family

class Family(family.Family): def __init__(self): family.Family.__init__(self) self.name = 'dota2wiki' self.langs = { 'en': u'www.dota2wiki.com', }

self.namespaces[4] = self.namespaces.get(4, {}) self.namespaces[4][u'en'] = [u'Dota 2 Wiki'] self.namespaces[5] = self.namespaces.get(5, {}) self.namespaces[5][u'en'] = [u'Dota 2 Wiki talk'] self.namespaces[6] = self.namespaces.get(6, {}) self.namespaces[6][u'en'] = [u'File'] self.namespaces[7] = self.namespaces.get(7, {}) self.namespaces[7][u'en'] = [u'File talk'] self.namespaces[102] = self.namespaces.get(102, {}) self.namespaces[102][u'en'] = [u'Property'] self.namespaces[103] = self.namespaces.get(103, {}) self.namespaces[103][u'en'] = [u'Property talk'] self.namespaces[108] = self.namespaces.get(108, {}) self.namespaces[108][u'en'] = [u'Concept'] self.namespaces[109] = self.namespaces.get(109, {}) self.namespaces[109][u'en'] = [u'Concept talk'] self.namespaces[500] = self.namespaces.get(500, {}) self.namespaces[500][u'en'] = [u'Guides'] self.namespaces[501] = self.namespaces.get(501, {}) self.namespaces[501][u'en'] = [u'Guides talk']

def scriptpath(self, code): return { 'en': u'', }[code]

def version(self, code): return { 'en': u'1.18.4', }[code]

user-config.py
mylang='en' family = 'dota2wiki' usernames['dota2wiki']['en']=u'KrooBot' console_encoding = 'utf-8'

bulkUpload.py
import os, sys, time import re import urllib import mimetypes import wikipedia as pywikibot import config, query import upload

from bulkUpload_conf import *

if len(sys.argv) < 2: print 'Please specify a folder or mp3 as argument.' sys.exit(1)

failedItems = list successItems = list

def uploadFile(f): global failedItems global successItems try: if os.path.abspath(f) != None: fileName = os.path.abspath(f) print "Uploading: " + fileName try: bot = upload.UploadRobot(url=fileName, description=config["uploadText"], keepFilename=True, useFilename=destinationFileName(os.path.basename(f)), verifyDescription=False, ignoreWarning=True) bot.run print "Done." successItems.append(fileName) except: print fileName print "Upload failed." failedItems.append(fileName) except: print f + "... not found" def passthrough(f): if not os.path.exists(f): print 'Warning:', f, 'doesn\'t exist; skipping.' elif os.path.isdir(f): if f[-1] != os.sep: f += os.sep for i in os.listdir(f): passthrough(f + i)	elif os.path.isfile(f) and len(f) > 4: if f[-4:].lower == '.mp3': uploadFile(f) else: print "This is not an MP3."

for f in sys.argv[1:]: passthrough(f) print "All done."

for winners in successItems: print winners + "... UPLOADED" if len(failedItems) != 0: for losers in failedItems: print losers + "... FAILED" print `len(failedItems)` if (raw_input("Enter \"Y\" to re-try uploading the failed items.\n").upper == "Y"): for losers in failedItems: uploadFile(losers)

bulkUpload_conf.py
config = { 'uploadText': '== Summary ==\nVoice file from Dota 2.\n\n== Licensing ==\n' }

def destinationFileName(fileName): return fileName #return "dlc stormspirit killing spree " + fileName #return fileName[:-4] + " icon.png" # e.g. 'stun.png' -> 'stun icon.png'