3 from decimal
import Decimal
4 from feed
import XmlFeed
7 return Region(XmlFeed('http://api.erepublik.com/v2/feeds/regions/%d' % int(id)))
10 id = map.get_region_id(name
)
18 return from_id(dict['id'])
21 """A region of Erepublik"""
23 def __init__(self
, f
):
24 self
.id = f
.int('/region/id')
25 self
.name
= f
.text('/region/name')
26 self
.population
= f
.int('/region/citizen-count')
27 self
.country
= {'name': map.get_country_name(f.int('/region/country/id')), 'id': f.int('/region/country/id')}
29 hospitals
= f
.elements('/region/buildings/hospitals/hospital')
35 'area': h
.int('area-of-effect'), 'budget': h
.int('wellness-budget'), 'quality': h
.int('customization-level'),
36 'max_heal': h
.int('max-heal-per-citizen')} for h
in hospitals
]
38 defense
= f
.elements('/region/buildings/defense-systems/defense-system')
44 'area': ds
.int('area-of-effect'), 'bonus': ds
.int('defense-bonus'), 'quality': ds
.int('customization-level'),
45 'durability': ds
.int('durability')} for ds
in defense
]
47 self
.raw_materials
= f
.text('/region/raw-materials/name')
50 'country': {'name': map.get_country_name(neighbour.int('country/id')), 'id': neighbour.int('country/id')}
,
51 'region': {'name': map.get_region_name(neighbour.int('region/id')), 'id': neighbour.int('region/id')}
}
52 for neighbour
in f
.elements('/region/neighbours/neighbour')]
54 self
.attack_cost
= 25 + Decimal(self
.population
) / 10
57 return '[%d] %s' % (self
.id, self
.name
)