Skip to content

Instantly share code, notes, and snippets.

@yanmhlv
Created August 24, 2013 18:39
Show Gist options
  • Save yanmhlv/6329765 to your computer and use it in GitHub Desktop.
Save yanmhlv/6329765 to your computer and use it in GitHub Desktop.
# coding: utf-8
import collections
import re
buildings = collections.defaultdict(dict)
with open('travian/buildings.txt') as fh:
for line in fh.readlines():
if re.match(r'#\s.', line):
name = line[2:-1]
else:
data = re.split('\s', line)
[data.remove(item) for item in data[:] if item is '']
datalist = buildings[name].get('data', [])
datalist.append(data)
buildings[name]['data'] = datalist
if re.match(r'#Sum', line):
summary = re.split('\s', line[5:])
[summary.remove(item) for item in summary[:] if item is '']
buildings[name]['summary'] = summary
from pprint import pprint
pprint(buildings, width = 120)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment