#!/usr/bin/python import httplib, mimetypes, os.path # Variables to change wowdir = '/home/gregstoll/.cedega/World of Warcraft/c_drive/Program Files/World of Warcraft' serverName = 'gregstoll.dyndns.org' serverPath = '/gwyddentelaid/receiveGuildData.cgi' def post_multipart(host, selector, fields, files): """ Post fields and files to an http host as multipart/form-data. fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return the server's response page. """ content_type, body = encode_multipart_formdata(fields, files) h = httplib.HTTPConnection(host) headers = { 'User-Agent': 'Gwydden Telaid guild data', 'Content-Type': (content_type + '; charset=utf-8') } h.request('POST', selector, body, headers) res = h.getresponse() #print "status is %d, reason is %s" % (res.status, res.reason) #print "headers is %s" % str(res.msg) return res.read() def encode_multipart_formdata(fields, files): """ fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return (content_type, body) ready for httplib.HTTP instance """ BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' CRLF = '\r\n' L = [] for (key, value) in fields: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"' % key) L.append('') L.append(value) for (key, filename, value) in files: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)) L.append('Content-Type: %s' % get_content_type(filename)) L.append('') L.append(value) L.append('--' + BOUNDARY + '--') L.append('') body = CRLF.join(L) content_type = 'multipart/form-data; boundary=%s' % BOUNDARY return content_type, body def get_content_type(filename): return mimetypes.guess_type(filename)[0] or 'application/octet-stream' def sendGuildInfoFile(filename): #print "a\n" fileData = file(filename).read() #print "hello" #print "fileData is %s" % fileData fileData = fileData.decode('utf_8').encode('utf_7') output = post_multipart(serverName, serverPath, [], [('file', filename, fileData)]) #print "output is %s" % output if (__name__ == '__main__'): # For testing only. saveDataPath = os.path.join(wowdir, r'WTF/Account') accountDirs = [os.path.join(saveDataPath, fileOrDir) for fileOrDir in os.listdir(saveDataPath) if os.path.isdir(os.path.join(saveDataPath, fileOrDir))] for accountDir in accountDirs: try: guildDataInfoPath = os.path.join(accountDir, r'SavedVariables/GuildInfoTable.lua') if (os.path.exists(guildDataInfoPath)): sendGuildInfoFile(guildDataInfoPath) except: pass