Sentielo
Advanced OT User
- Joined
- Feb 3, 2008
- Messages
- 2,388
- Reaction score
- 226
Hi,
Several years ago I posted a monster package with accurate loot.
Stian - a former Otland member - created a monster loot parser written in Python code for me in order to do so.
With this Monster Parser I could convert creature loot details from tibia-stats.com to xml.
I remember python version 2.4.4 was used to execute it.
Somehow the program is not working anymore.
It gives a Syntax Error - invalid syntax - in line 539: "buf += string % int(extra2 * (0.6 if x == 0 else (0.3 if x == 1 else 0.1)))"
Does anybody know how to solve this problem?
The parser contains the following code:
Thank you in advance, Sentielo
Several years ago I posted a monster package with accurate loot.
Stian - a former Otland member - created a monster loot parser written in Python code for me in order to do so.
With this Monster Parser I could convert creature loot details from tibia-stats.com to xml.
I remember python version 2.4.4 was used to execute it.
Somehow the program is not working anymore.
It gives a Syntax Error - invalid syntax - in line 539: "buf += string % int(extra2 * (0.6 if x == 0 else (0.3 if x == 1 else 0.1)))"
Does anybody know how to solve this problem?
The parser contains the following code:
Python:
#!/usr/bin/env python
# CODE By Stian, VAPus Labs
import os.path, glob, re
import urllib
from HTMLParser import HTMLParser
from sgmllib import SGMLParser
print "Tibia loot stat fetcher by Stian!\n"
global HANDLE_MUGS
HANDLE_MUGS = 0
shopkeeper = ""
ids = {'gold coin': '2148', 'worm': '3976'}
### Hacked items to match items.xml
ids["warmaster's wristguards"] = '11322'
ids["countess sorrow's frozen tear"] = '6536'
ids["geomancer's robe"] = '12414'
ids["geomancer's staff"] = '12419'
ids["kongra's shoulderpad"] = '12427'
ids["hunter's quiver"] = '12425'
ids["the stomper"] = '8929'
ids["jewelled belt"] = '12426'
ids["dirty turban"] = '12412'
ids["dragon's tail"] = '12413'
ids["noble turban"] = '12442'
ids["magic light wand"] = '2162'
ids["the devileye"] = '8852'
ids["the ironworker"] = '8853'
ids["morgaroth's heart"] = '5943'
ids["mr. punish's handcuffs"] = '6537'
ids["the handmaiden's protector"] = '6539'
ids["claw of 'the noxious spawn'"] = '10309'
ids["mysterious voodoo skull"] = '5669'
ids["spirit container"] = '5884'
ids["flask of warrior's sweat"] = '5885'
ids["small blue pillow"] = '1681'
ids["small enchanted amethyst"] = '7762'
ids["spider silk"] = '5879'
ids["remains of a fish"] = '2240'
ids["demon trophy"] = '7393'
ids["potato"] = '8838'
ids["small enchanted ruby"] = '7760'
ids["spooky blue eye"] = '10559'
ids["tusk"] = '8614'
ids['jalapeno pepper'] = '8844'
ids["lion's mane"] = '10608'
ids["pitchfork"] = '2548'
ids["charmer's tiara"] = '3971'
ids["pair of earmuffs"] = '7459'
ids["mini mummy"] = '11207'
ids["war drum"] = '3953'
ids["piece of massacre's shell"] = '6540'
ids["some leaves"] = '2244'
ids["energy spike sword"] = '7869'
ids["dragon priest's wandtip"] = '11361'
ids["weaver's wandtip"] = '11314'
ids["widow's mandibles"] = '11328'
ids["wailing widow's necklace"] = '11329'
ids["explorer brooch"] = '4873'
ids["giant shimmering pearl"] = '7632'
ids["bloody pincers"] = '10550'
ids["heaven blossom"] = '5921'
monsterids = {} # Never ever remove
monsterids["worker golem"] = {'rusty armor':9809}
monsterids["hellspawn"] = {'rusty armor':9809}
monsterids["massive earth elemental"] = {'rusty armor':9809}
monsterids["mutated bat"] = {'rusty armor':9809}
monsterids["werewolf"] = {'rusty armor':9809}
monsterids["leviathan"] = {'rusty armor':9809}
monsterids["massive energy elemental"] = {'rusty armor':9809}
monsterids["war golem"] = {'rusty armor':9809}
monsterids["young sea serpent"] = {'rusty armor':9809}
monsterids["plaguesmith"] = {'rusty armor':9810}
monsterids["phantasm"] = {'rusty armor':9810}
monsterids["ushuriel"] = {'rusty armor':9810}
monsterids["juggernaut"] = {'rusty armor':9810}
monsterids["hellgorak"] = {'rusty armor':9810}
monsterids["grim reaper"] = {'rusty armor':9810}
monsterids["annihilon"] = {'rusty armor':9810}
monsterids["madareth"] = {'rusty armor':9810}
monsterids["zugurosh"] = {'rusty armor':9810}
monsterids["hellhound"] = {'rusty armor':9810}
monsterids["blightwalker"] = {'rusty armor':9810}
monsterids["ghastly dragon"] = {'rusty armor':9810}
monsterids["undead dragon"] = {'rusty armor':9810}
monsterids["lost soul"] = {'rusty armor':9810}
monsterids["medusa"] = {'rusty armor':9810}
monsterids["zulazza the corruptor"] = {'rusty armor':9810}
monsterids["ghastly dragon"] = {'rusty armor':9810}
monsterids["worker golem"] = {'rusty legs':9812}
monsterids["leviathan"] = {'rusty legs':9812}
monsterids["hellgorak"] = {'rusty legs':9813}
monsterids["madareth"] = {'rusty legs':9813}
monsterids["zugurosh"] = {'rusty legs':9813}
monsterids["fury"] = {'rusty legs':9813}
monsterids["frost dragon"] = {'book':1976}
monsterids["orc shaman"] = {'book':1958}
monsterids["priestess"] = {'book':1962}
monsterids["dragon lord"] = {'book':1976}
monsterids["ghost"] = {'book':1962}
monsterids["novice of the cult"] = {'book':1962}
monsterids["acolyte of the cult"] = {'book':1962}
monsterids["adept of the cult"] = {'book':1962}
monsterids["enlightened of the cult"] = {'book':1962}
monsterids["green djinn"] = {'book':1965}
monsterids["blue djinn"] = {'book':1963}
monsterids["barbarian brutetamer"] = {'book':1958}
monsterids["demodras"] = {'book':1976}
monsterids["grynch clan goblin"] = {'bag':6497}
monsterids["adept of the cult"] = {'music sheet':6089}
monsterids["novice of the cult"] = {'music sheet':6087}
monsterids["acolyte of the cult"] = {'music sheet':6088}
monsterids["enlightened of the cult"] = {'music sheet':6090}
monsterids["pirate buccaneer"] = {'treasure map':5706}
monsterids["pirate cutthroat"] = {'treasure map':5706}
monsterids["pirate marauder"] = {'treasure map':5706}
monsterids["pirate corsair"] = {'treasure map':5706}
maxcount = {} # Countmaxes - never remove
maxcount["bear"] = {2666:'4', 2671:'3'}
maxcount["crazed beggar"] = {2666:'2'}
maxcount["wolf"] = {2666:'2'}
maxcount["nightmare scion"] = {2666:'4'}
maxcount["terror bird"] = {2666:'3'}
maxcount["chicken"] = {2666:'2'}
maxcount["behemoth"] = {2666:'6'}
maxcount["carrion worm"] = {2666:'2'}
maxcount["elephant"] = {2666:'4', 2671:'3'}
maxcount["hyaena"] = {2666:'2'}
maxcount["panda"] = {2666:'4', 2671:'2'}
maxcount["pig"] = {2666:'4'}
maxcount["rabbit"] = {2666:'2'}
maxcount["valkyrie"] = {2666:'3'}
maxcount["scarab"] = {2666:'2'}
maxcount["tiger"] = {2666:'3'}
maxcount["lion"] = {2666:'4', 2671:'2'}
maxcount["destroyer"] = {2666:'6'}
maxcount["rotworm"] = {2666:'2', 2671:'2'}
maxcount["polar bear"] = {2666:'4', 2671:'2'}
maxcount["silver rabbit"] = {2666:'2'}
maxcount["winter wolf"] = {2666:'2'}
maxcount["deer"] = {2666:'4', 2671:'2'}
maxcount["undead gladiator"] = {2666:'2'}
maxcount["mammoth"] = {2671:'3'}
maxcount["sheep"] = {2666:'4'}
maxcount["massacre"] = {2666:'9'}
maxcount["orc rider"] = {2666:'3'}
maxcount["tiquandas revenge"] = {2666:'50', 2671:'8'}
maxcount["frost giant"] = {2666:'2'}
maxcount["black sheep"] = {2666:'5'}
maxcount["stonecracker"] = {2666:'2'}
maxcount["deadeye devious"] = {2666:'3'}
maxcount["lethal lissy"] = {2666:'2'}
maxcount["gnarlhound"] = {2666:'3'}
maxcount["draken abomination"] = {2666:'4'}
maxcount["hydra"] = {2671:'4'}
maxcount["nightmare"] = {2671:'2'}
maxcount["dark torturer"] = {2671:'2'}
maxcount["hellhound"] = {2671:'14'}
maxcount["juggernaut"] = {2671:'8'}
maxcount["war wolf"] = {2671:'2'}
maxcount["barbarian brutetamer"] = {2671:'3'}
maxcount["frost giantess"] = {2671:'2'}
maxcount["dragon"] = {2672:'3'}
maxcount["frost dragon"] = {2672:'5'}
maxcount["dragon lord"] = {2672:'5'}
maxcount["wyrm"] = {2672:'3'}
maxcount["wyvern"] = {2672:'3'}
maxcount["demodras"] = {2672:'10'}
### Addon pieces
maxcount["hero"] = {5911:'3'}
maxcount["fury"] = {5911:'3'}
maxcount["infernalist"] = {5911:'3'}
maxcount["barbarian bloodwalker"] = {5911:'3'}
maxcount["undead jester"] = {5911:'3'}
maxcount["green djinn"] = {5910:'3'}
maxcount["efreet"] = {5910:'3'}
maxcount["undead jester"] = {5910:'3'}
maxcount["giant spider"] = {5879:'3'}
maxcount["crystal spider"] = {5879:'3'}
maxcount["hide"] = {5879:'3'}
maxcount["the old widow"] = {5879:'3'}
maxcount["damaged worker golem"] = {5880:'3'}
maxcount["worker golem"] = {5880:'3'}
maxcount["war golem"] = {5880:'3'}
maxcount["dwarf"] = {5880:'3'}
maxcount["dwarf guard"] = {5880:'3'}
maxcount["dwarf soldier"] = {5880:'3'}
maxcount["stone golem"] = {5880:'3'}
maxcount["ushuriel"] = {5880:'3'}
maxcount["jagged earth elemental"] = {5880:'3'}
maxcount["behemoth"] = {5893:'3'}
maxcount["stonecracker"] = {5893:'3'}
maxcount["lizard sentinel"] = {5876:'3'}
maxcount["lizard templar"] = {5876:'3'}
maxcount["lizard snakecharmer"] = {5876:'3'}
maxcount["battlemaster zunzu"] = {5876:'3'}
maxcount["lizard dragon priest"] = {5876:'3'}
maxcount["lizard high guard"] = {5876:'3'}
maxcount["lizard legionnaire"] = {5876:'3'}
maxcount["lizard zaogun"] = {5876:'3'}
maxcount["lizard chosen"] = {5876:'3'}
maxcount["minotaur"] = {5878:'3'}
maxcount["minotaur archer"] = {5878:'3'}
maxcount["minotaur guard"] = {5878:'3'}
maxcount["minotaur mage"] = {5878:'3'}
maxcount["apprentice sheng"] = {5878:'3'}
maxcount["bear"] = {5902:'3'}
maxcount["wasp"] = {5902:'3'}
maxcount["grynch clan goblin"] = {5902:'3'}
maxcount["chicken"] = {5890:'3'}
maxcount["grynch clan goblin"] = {5902:'3'}
maxcount["bear"] = {5896:'3'}
maxcount["war wolf"] = {5897:'3'}
maxcount["werewolf"] = {5897:'3'}
maxcount["wolf"] = {5897:'3'}
maxcount["dragon lord"] = {5948:'3'}
maxcount["demodras"] = {5948:'3'}
maxcount["bat"] = {5894:'3'}
maxcount["mutated bat"] = {5894:'3'}
maxcount["grynch clan goblin"] = {5894:'3'}
maxcount["kongra"] = {5883:'3'}
maxcount["sibang"] = {5883:'3'}
maxcount["merlkin"] = {5883:'3'}
maxcount["elf arcanist"] = {5922:'3'}
maxcount["lizard sentinel"] = {5881:'3'}
maxcount["lizard templar"] = {5881:'3'}
maxcount["lizard snakecharmer"] = {5881:'3'}
maxcount["battlemaster zunzu"] = {5881:'3'}
maxcount["lizard dragon priest"] = {5881:'3'}
maxcount["lizard high guard"] = {5881:'3'}
maxcount["lizard legionnaire"] = {5881:'3'}
maxcount["lizard zaogun"] = {5881:'3'}
maxcount["lizard chosen"] = {5881:'3'}
maxcount["chizzoron the distorter"] = {5881:'3'}
maxcount["dragon lord"] = {5882:'3'}
maxcount["quara constrictor"] = {5895:'3'}
maxcount["quara constrictor scout"] = {5895:'3'}
maxcount["quara hydromancer"] = {5895:'3'}
maxcount["quara hydromancer scout"] = {5895:'3'}
maxcount["quara mantassin"] = {5895:'3'}
maxcount["quara mantassin scout"] = {5895:'3'}
maxcount["quara pincher"] = {5895:'3'}
maxcount["quara pincher scout"] = {5895:'3'}
maxcount["quara predator"] = {5895:'3'}
maxcount["quara predator scout"] = {5895:'3'}
maxcount["thul"] = {5895:'3'}
maxcount["blue djinn"] = {5912:'3'}
maxcount["marid"] = {5912:'3'}
maxcount["yakchal"] = {5912:'3'}
maxcount["undead jester"] = {5912:'3'}
maxcount["bonebeast"] = {5925:'3'}
maxcount["dreadbeast"] = {5925:'3'}
maxcount["undead dragon"] = {5925:'3'}
maxcount["dracola"] = {5925:'3'}
maxcount["tortoise"] = {5899:'3'}
maxcount["beholder"] = {5898:'3'}
maxcount["braindeath"] = {5898:'3'}
maxcount["the evil eye"] = {5898:'3'}
maxcount["ghoul"] = {5913:'3'}
maxcount["undead jester"] = {5913:'3'}
maxcount["barbarian headsplitter"] = {5913:'3'}
maxcount["barbarian skullhunter"] = {5913:'3'}
maxcount["mummy"] = {5914:'3'}
maxcount["undead jester"] = {5914:'3'}
maxcount["ghost"] = {5909:'3'}
maxcount["spectre"] = {5909:'3'}
maxcount["undead jester"] = {5909:'3'}
maxcount["elf"] = {5921:'3'}
maxcount["pirate marauder"] = {6098:'3'}
maxcount["pirate cutthroat"] = {6098:'3'}
maxcount["pirate buccaneer"] = {6098:'3'}
maxcount["pirate corsair"] = {6098:'3'}
maxcount["pirate marauder"] = {6126:'3'}
maxcount["pirate cutthroat"] = {6126:'3'}
maxcount["pirate buccaneer"] = {6126:'3'}
maxcount["pirate corsair"] = {6126:'3'}
maxcount["pirate marauder"] = {6097:'3'}
maxcount["pirate cutthroat"] = {6097:'3'}
maxcount["pirate buccaneer"] = {6097:'3'}
maxcount["pirate corsair"] = {6097:'3'}
maxcount["grim reaper"] = {6500:'3'}
maxcount["hellspawn"] = {6500:'3'}
maxcount["plaguesmith"] = {6500:'3'}
maxcount["nightmare"] = {6500:'3'}
maxcount["dark torturer"] = {6500:'3'}
maxcount["fury"] = {6500:'3'}
maxcount["hellfire fighter"] = {6500:'3'}
maxcount["hellhound"] = {6500:'3'}
maxcount["lost soul"] = {6500:'3'}
maxcount["phantasm"] = {6500:'3'}
maxcount["ushuriel"] = {6500:'3'}
maxcount["zugurosh"] = {6500:'3'}
maxcount["destroyer"] = {6500:'3'}
maxcount["hand of cursed fate"] = {6500:'3'}
maxcount["juggernaut"] = {6500:'3'}
maxcount["spectre"] = {6500:'3'}
maxcount["hellgorak"] = {6500:'3'}
maxcount["betrayed wraith"] = {6500:'3'}
maxcount["defiler"] = {6500:'3'}
maxcount["diabolic imp"] = {6500:'3'}
maxcount["undead dragon"] = {6500:'3'}
maxcount["golgordan"] = {6500:'3'}
maxcount["latrivan"] = {6500:'3'}
maxcount["madareth"] = {6500:'3'}
maxcount["ghazbaran"] = {6500:'15'}
maxcount["massacre"] = {6500:'3'}
maxcount["morgaroth"] = {6500:'12'}
maxcount["orshabaal"] = {6500:'15'}
maxcount["the handmaiden"] = {6500:'3'}
maxcount["dracola"] = {6500:'3'}
maxcount["countess sorrow"] = {6500:'3'}
maxcount["the imperor"] = {6500:'3'}
maxcount["the plasmother"] = {6500:'3'}
maxcount["mr. punish"] = {6500:'3'}
maxcount["ghastly dragon"] = {6500:'3'}
### Stuff to ignore
ignore = {}
ignore["nothing"] =""
"""
try:
shopkeeper = open('shopkeeper.txt')
except:
print "We have a problem, i don't find your file, but i try to look for ANY .xml file now!"
files = glob.glob("*.xml")
if len(files):
print "Found: %s" % files[0]
print "(Full list: \"", '", "'.join(files),"\")"
shopkeeper = open(files[0])
else:
print "Nothing :("
raw_input()
class GetItemsXML(SGMLParser):
def reset(self):
SGMLParser.reset(self)
self.names = {}
self.ids = {}
def start_item(self, attrs):
id = 0
fromid = 0
to = 0
name = ""
for thing in attrs:
if thing[0] == "id":
id = thing[1]
elif thing[0] == "name":
name = thing[1]
elif thing[0] == "fromid":
fromid = thing[1]
elif thing[0] == "toid":
to = thing[1]
if(not fromid and not to):
if not name in self.names:
self.names[name] = self.makeName(id, name)
self.ids[name] = self.makeID(id)
else:
for id in range(int(fromid), int(to)):
if not name in self.names:
self.names[name] = self.makeName(str(id), name)
self.ids[name] = self.makeID(str(id))
def makeID(self, id):
# Mugs:
if(HANDLE_MUGS and int(id) > 20000):
id=self.ids["mug"]+","+str(int(id)-20000)
return id
def makeName(self, id, name):
# Mugs:
if(HANDLE_MUGS and int(id) > 20000):
name = "mug of "+name
return name
itemParse = GetItemsXML()
itemParse.feed(shopkeeper.read())
ids = itemParse.ids
print ids
ignore = {}
ignore["nothing"] =""
names = itemParse.names
"""
class Parser(HTMLParser):
def reset(self):
HTMLParser.reset(self)
self.care = 0
self.kills = 0
self.nextName = 0
self.nextKills = 0
self.name = ""
self.tagA = 0
self.tagOn = 0
self.loot = []
def getTag(self, attrs, what):
for x in attrs:
if x[0] == what:
return x[1]
def handle_starttag(self, tag, attrs):
if tag == "div":
if self.getTag(attrs, 'class') == "MON_name":
self.nextName = 1
if self.getTag(attrs, 'class') == "MON_icon_desc":
self.nextKills = 1
if self.getTag(attrs, 'class') == "MON_loot":
self.care = 1
self.tagA = self.tagOn + 1
self.tagOn += 1
if tag == "td" and self.care:
self.care += 1
def handle_data(self, data):
if self.nextName:
self.name = data.strip()
self.nextName = 0
elif self.nextKills:
self.kills = data.strip().replace('+', '')
self.nextKills = 0
elif self.care > 1:
self.loot.append(data.strip())
def handle_endtag(self, tag):
if tag == "div":
if self.tagOn == self.tagA:
self.care = 0
self.tagOn -= 1
if tag == "td" and self.care:
self.care -= 1
runmode = int(raw_input("Run-mode(1 = from 490 to 985, 2 = one mid)? "))
updatemode = raw_input("Auto-update files (start folder/monster/*/monster-name.xml)(y/n)? ")
update = 0
fromid = 0
to = 0
if updatemode == "y":
update = 1
if runmode == 1:
fromid = 490
to = 985
print "Running...\n"
for mid in range(fromid, to+1):
if runmode == 2:
mid = int(raw_input("Mid? "))
print "Running...\n"
wikia = urllib.urlopen("http://www.tibia-stats.com/index.php?akcja=2001&mid="+str(mid))
parse = Parser()
parse.loot = []
parse.feed(wikia.read().replace("text-align:left;", '').replace("’", "'").replace("ñ", 'n'))
if not parse.name:
print "MID %s not found!" % mid
continue
if not parse.kills:
print "%s have never been killed!" % parse.name
continue
if runmode == 1 and int(parse.kills) < 10:
print "%s killed less then 10 times" % parse.name
continue
print parse.name, "(Killed %s+ times)" % parse.kills
print ""
buf = "<loot>\n"
string = ""
items = 0
total = len(parse.loot) / 4
if total < 35:
bagid = "1987"
maxfactor = 0.55
else:
bagid = "1988"
maxfactor = 0.33
maxitems = int(total * maxfactor)
inbag = 0
bagitems = 0
for x in range(0, len(parse.loot), 4):
string = ""
parse.loot[x] = parse.loot[x].replace('coins', 'coin').lower()
if items >= maxitems and not inbag:
string += ' <item id="'+bagid+'" chance="100000"><!-- bag -->'+"\n <inside>\n"
inbag = 1
if not parse.loot[x] in ids:
if not parse.loot[x] in ignore:
print "WARNING: Item `%s` not found!" % parse.loot[x]
continue
replicate = 1
if inbag:
string += " "
if parse.name in monsterids and parse.loot[x] in monsterids[parse.name]:
string += ' <item id="%s" ' % monsterids[parse.name][parse.loot[x]]
else:
string += ' <item id="%s" ' % ids[parse.loot[x]]
extra = 0
extra2 = 0
for y in range(1, 4):
z = x + y
if y == 1 and parse.loot[z] != 1:
if int(parse.loot[z]) > 100:
extra = int(parse.loot[z])
string += 'countmax="%s" '
elif parse.name in maxcount and int(ids[parse.loot[x]]) in maxcount[parse.name]:
string += 'countmax="%s" ' % maxcount[parse.name][int(ids[parse.loot[x]])]
elif int(parse.loot[z]) > 1:
string += 'countmax="%s" ' % parse.loot[z]
if y == 2:
chance = float(parse.loot[z].replace(',', '.')) * 100000.0
chance = chance / int(parse.loot[z-1])
chance = int(round(chance / 25.0) * 25) + 500
if chance > 100000:
chance = 100000;
if chance < 25:
chance = 25
string += 'chance="%s" ' % chance
if y == 3:
string += "/><!-- %s -->" % parse.loot[x]
for x in range(0, replicate):
if extra:
while extra:
if extra > 100:
buf += string % 100
buf += "\n"
extra -= 100
total += 1
else:
buf += string % extra
buf += "\n"
extra = 0
elif extra2:
if replicate > 1:
buf += string % int(extra2 * (0.6 if x == 0 else (0.3 if x == 1 else 0.1)))
else:
buf += string % extra2
buf += "\n"
else:
buf += string
buf += "\n"
items += 1
if inbag:
bagitems += 1
if not inbag and items < total and items >= maxitems:
inbag = 1
buf += ' <item id="'+bagid+'" chance="100000"><!-- bag -->'+"\n <inside>\n"
if inbag:
buf += " </inside>\n </item>\n"
buf += "</loot>"
if update:
file = glob.glob("monster/*/%s.xml" % parse.name)
if not file:
print "WARNING: File for %s not found!" % parse.name
else:
obj = open(file[0], 'r')
dataobj = obj.read()
obj = open(file[0], 'w')
reg = re.compile(r'<loot>(.*)</loot>', re.M|re.S)
dataobj =reg.sub(buf, dataobj)
obj.write(dataobj)
obj.flush()
obj.close()
else:
print buf
parse.reset()
raw_input("All done (Press the Any key) ")
Thank you in advance, Sentielo