Dota 2 Wiki:Scripts/CosmeticParse

import re, linecache
 * 1) !/usr/bin/python

bundlename = 'The Timekeeper' hero = 'Templar Assassin' release = '2016-03-13' description = 'Some small trivia' creator = '[http:/linktoguy.com/ Guy Name]' availability = 'Set / Bundle / Treasure / Compendium'
 * 1) DEFINE######################
 * 1) DEFINE#END##################

output = open('output_bundle.txt', 'w') partnames = []

def main : bundle = getItem(bundlename)

parts = [] tmp_nextto = ''

for i in range (0, len(partnames)): tmp_nextto = tmp_nextto + '| setitem%d = %s\n' % (i+1,partnames[i]) parts.append(getItem(partnames[i]))

bundle.nextto = tmp_nextto output.write(fillinfo(bundle))

for i in range (0, len(parts)): parts[i].nextto = tmp_nextto output.write(fillinfo(parts[i])) output.close

def getItem (name): print (name + '\n') item = Item name = name.replace(' ', '\ ') regex = '\\"name\\"\\s*\\"(%s)\\"' % (name) lino = 0

input = open('items_game.txt', 'r') for line in input: lino = lino + 1 match = re.search (regex, line) if match: item.name = match.group(1) item.index = getIndex(lino) item.rarity = getRarity(lino) item.prefab = getPrefab(lino) item.partof = bundlename if item.prefab == 'bundle': item.slot = 'Bundle' getParts(lino) elif item.prefab == 'wearable': item.slot = getSlot(lino) elif item.prefab == 'loading_screen': item.slot = 'Loading Screen' break

input.close return item

def getIndex (lino): line = linecache.getline('items_game.txt', lino - 2) match = re.search(r'\"(.*)\"', line) return match.group(1)

def getPrefab (lino): while True: lino = lino + 1 line = linecache.getline('items_game.txt', lino) match = re.search(r'\"prefab\"\s*\"(.*)\"', line) if match: print (str(lino) + line) return match.group(1)

def getSlot (lino): while True: lino = lino + 1 line = linecache.getline('items_game.txt', lino) match = re.search(r'\"item\_slot\"\s*\"(.*)\"', line) if match: print (str(lino) + line) return match.group(1).replace('_', ' ').title

def getRarity (lino): while True: lino = lino + 1 line = linecache.getline('items_game.txt', lino) match = re.search(r'\"item\_rarity\"\s*\"(.*)\"', line) if match: return match.group(1).replace('_', ' ').title

def getParts (lino): listart = lino liend = 0

while True: listart = listart + 1 line = linecache.getline('items_game.txt', listart) if re.match(r'\s*\"bundle\"', line): listart = listart + 1 break

liend = listart

while True: liend = liend + 1 line = linecache.getline('items_game.txt', liend) if re.match (r'\s*\}', line): break else: match = re.search(r'\"(.*)\"\s*\"[0-9]\"', line) partnames.append(match.group(1))

class Item: index = '' name = '' partof = '' nextto = '' prefab = '' slot = '' rarity = ''

def fillinfo (item): out = \n\n % (item.name, item.name, hero, item.slot, item.rarity, description, creator, availability, release, item.index, item.partof, item.nextto)

return out

if __name__ == "__main__": main