Advertisement
Straevaras

Terraria Bingo List Formatter

Jun 20th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. categoryCounter = {}
  2.  
  3. def main():
  4.  
  5.     f = open('bingo list categories.txt')
  6.     fout = open('formatout.txt', 'w')
  7.  
  8.  
  9.     fout.write('var bingoList=[];')
  10.     groupCounter = -1
  11.     elementArray = []
  12.     for line in f:
  13.         if line[0] == '[':
  14.             groupCounter += 1
  15.             if groupCounter != 0:
  16.                 fout.write('bingoList[{}]=[{}];'.format(groupCounter, ','.join(elementArray)))
  17.             elementArray = []
  18.         else:
  19.             tokens = line.strip().split(',')
  20.             name = tokens[0].replace(';',',')
  21.             for type in tokens[1:]:
  22.                 count(type)
  23.             types = '[{}]'.format(','.join([r'\"' + i + r'\"' for i in tokens[1:]]))
  24.             element = r'{{name:\"{}\",types:{}}}'.format(name, types)
  25.             elementArray.append(element)
  26.     fout.write('$(function(){srl.bingo(bingoList,5);});')
  27.     report()
  28.  
  29. def count(cat):
  30.     if cat in categoryCounter:
  31.         categoryCounter[cat] += 1
  32.     else:
  33.         categoryCounter[cat] = 1
  34.        
  35. def report():
  36.     once = []
  37.     twice = []
  38.     for key in categoryCounter:
  39.         if categoryCounter[key] == 1:
  40.             once.append(key)
  41.         elif categoryCounter[key] == 2:
  42.             twice.append(key)
  43.    
  44.     for key in sorted(once):
  45.         print key, 'is only used once.'
  46.     print '--------------------'
  47.     for key in sorted(twice):
  48.         print key, 'is only used twice.'
  49.            
  50. if __name__ == "__main__":
  51.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement