Mercurial > eagle-eye
diff pyikriam/example.py @ 177:6adad3bcca78
Refactory to functions for sychronizing object attributes with pages.
- We add more building types.
- All of them need to sync attributes with content of Ikariam's online page.
- These functions are refactoried to functions.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 02 Nov 2008 15:14:51 +0800 |
parents | 3ba3edda6d1e |
children | bf4ddf5bffb9 |
line wrap: on
line diff
--- a/pyikriam/example.py Sun Nov 02 11:32:59 2008 +0800 +++ b/pyikriam/example.py Sun Nov 02 15:14:51 2008 +0800 @@ -1,4 +1,5 @@ import sys +import buildings from ikariam import Ikariam if len(sys.argv) != 2: @@ -23,12 +24,15 @@ print 'sulfur is ' + city.sulfur print 'positions ' + repr(city.positions) -city.positions[0].sync() -city_attrs = ('level', 'occupied', 'rooms', 'growth', 'happiness', - 'interest_base', 'interest_research', 'interest_capital', - 'pop_citizens', 'pop_woodworkers', 'pop_specialworkers', - 'pop_scientists', 'is_upgrading', 'upgrade_uri') -for city_attr in city_attrs: - value = getattr(city.positions[0], city_attr) - print 'positions[0].%s is %s' % (city_attr, str(value)) - pass +for idx, pos in enumerate(city.positions): + if not isinstance(pos, buildings.position): + continue + pos.sync() + building_attrs = filter(lambda attr: not attr[0].startswith('_'), + pos.__dict__.items()) + building_attrs.sort(key=lambda x: x[0]) + print + print 'positions[%d]' % (idx) + for building_attr, value in building_attrs: + print '\t%s: %s' % (building_attr, repr(value)) + pass