-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuploadFile.py
More file actions
21 lines (19 loc) · 857 Bytes
/
uploadFile.py
File metadata and controls
21 lines (19 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/python -OO
# -*- coding: utf-8 -*-
import os, wikiUpload, urllib2, hashlib
def fileURL(filename, siteaddress=r'http://wiki.teamfortress.com/w/images/'):
filenamehash = hashlib.md5(filename.replace(' ', '_')).hexdigest()
return siteaddress + filenamehash[:1] + '/' + filenamehash[:2] + '/' + filename.replace(' ', '_')
def uploadFile(file, title, description, username, password, category='', wikiURL='http://wiki.tf2.com/w/', license='', fileprefix='', filesuffix='', overwrite=False):
if username is None or password is None:
return
uploader = wikiUpload.wikiUploader(username, password, wikiURL)
try:
print 'Uploading', file, 'as', title, '...'
try:
uploader.upload(file, title, description + category, license, overwrite=overwrite)
except:
print 'Failed', file
return None
except KeyboardInterrupt:
print 'Stopped.'