Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, re
- from urllib import request
- def writeSQLQuery(file, entry, copper, silver, gold) :
- money = gold * 10000 + silver * 100 + copper
- minMoney = 0
- maxMoney = 0
- if (gold != 0 and silver != 0 and copper != 0) :
- minMoney = money - 50000
- maxMoney = money + 50000
- elif (gold != 0 and silver == 0 and copper == 0) or (gold == 0 and silver != 0) :
- minMoney = money - 500
- maxMoney = money + 500
- elif (gold == 0 and silver == 0) :
- minMoney = money - 5
- maxMoney = money + 5
- sqlQuery = "UPDATE creature_template SET mingold = " + str(minMoney) + ", maxgold = " + str(maxMoney)
- sqlQuery = sqlQuery + " WHERE entry = " + str(entry) + ";"
- print(sqlQuery)
- def parseMoney(entries, zoneId):
- fileSQL = open("D:/money_" + str(zoneId), 'w')
- print("OK")
- for element in entries :
- url = "http://www.wowhead.com/npc=" + str(element)
- copper = 0
- silver = 0
- gold = 0
- u = ""
- try :
- u = request.urlopen(str(url))
- except :
- print("Unable to parse entry " + str(element))
- continue
- #print("Parsing" + str(element))
- content = str(u.read())
- moneyTotal = 0
- globalMoneyRe = re.search(r'money x3D([0-9]*)', content)
- #print(globalMoneyRe)
- if globalMoneyRe :
- moneyTotal = int(globalMoneyRe.group(1))
- gold = int(moneyTotal / 10000)
- moneyTotal -= 10000 * gold
- silver = int(moneyTotal / 100)
- moneyTotal -= 100 * silver
- copper = int(moneyTotal)
- moneyTotal -= copper
- #print(str(gold) + \' \' + str(silver) + \' \' + str(copper))
- if(gold != 0 or silver != 0 or copper != 0):
- writeSQLQuery(fileSQL, element, copper, silver, gold)
- fileSQL.close()
- def parseEntriesInZone(zoneId) :
- url = "http://www.wowhead.com/zone=" + str(zoneId)
- u = ""
- try :
- u = request.urlopen(str(url))
- except :
- return 0
- print('OK')
- content = u.read()
- content = str(content)
- fileSQL = open("D:/Content.txt", 'w')
- #print(str(content))
- liste = list()
- globalRe = re.search(r"template: 'npc', id: 'npcs'.*?}.;", content)
- if globalRe :
- print("OK")
- globAsString = str(globalRe.group(0))
- fileSQL.write(globAsString)
- eachIdRe = re.search(r'"id":([0-9]*),', globAsString)
- while eachIdRe :
- print("Got" + str(eachIdRe.group(1)))
- liste.append(eachIdRe.group(1))
- globAsString = globAsString[eachIdRe.start() + len(eachIdRe.group(0)):]
- eachIdRe = re.search(r'"id":([0-9]*)', globAsString)
- parseMoney(liste, zoneId)
- parseEntriesInZone(5736)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement