]> jfr.im git - irc/rizon/acid.git/blob - pyva/src/main/python/erepublik/api/country.py
Import acidictive 4 and pyva plugin
[irc/rizon/acid.git] / pyva / src / main / python / erepublik / api / country.py
1 import feed
2 from feed import XmlFeed, get_json
3
4 country_feed = None
5
6 def get_cached_countries():
7 global country_feed
8
9 if country_feed == None:
10 country_feed = XmlFeed('http://api.erepublik.com/v2/feeds/countries/')
11
12 return country_feed
13
14 def from_id(id):
15 return get_json('http://api.1way.it/erep/country/%d' % int(id))
16
17 def from_name(name):
18 country_feed = get_cached_countries()
19
20 countries = country_feed.elements('/countries/country')
21 name = name.lower()
22
23 for c in countries:
24 if name == c.text('name').lower() or name == c.text('code').lower():
25 return from_id(c.text('id/text()'))
26
27 return None
28
29 def from_dict(dict):
30 return from_id(dict['id'])
31
32 def get_taxes(country_id):
33 return get_json('http://api.1way.it/erep/tax/%d' % country_id)
34
35 def get_regions(country_id):
36 return get_json('http://api.1way.it/erep/regions/%d' % country_id)