Created
August 24, 2013 18:39
-
-
Save yanmhlv/6329765 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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