]>
Commit | Line | Data |
---|---|---|
685e346e A |
1 | import feed |
2 | import utils | |
3 | from feed import XmlFeed | |
4 | ||
5 | def from_id(id): | |
6 | return Company(XmlFeed('http://api.erepublik.com/v2/feeds/companies/%d' % int(id))) | |
7 | ||
8 | def from_dict(dict): | |
9 | return from_id(dict['id']) | |
10 | ||
11 | class Company: | |
12 | """A company of eRepublik""" | |
13 | ||
14 | def __init__(self, f): | |
15 | self.id = f.int('/company/id') | |
16 | self.name = f.text('/company/name') | |
17 | self.industry = utils.get_industry(f.text('/company/industry/name')) | |
18 | self.country = { | |
19 | 'name': f.text('/company/country/name'), | |
20 | 'id': f.int('/company/country/id'), | |
21 | 'code': f.text('/company/country/code')} | |
22 | self.quality = f.int('/company/customization-level') | |
23 | self.is_for_sale = 'true' in f.text('/company/is-for-sale') | |
24 | ||
25 | self.job_offers = [{ | |
26 | 'country': job.text('country'), 'amount': job.int('number-of-jobs'), | |
27 | 'skill': job.int('required-skill')} | |
28 | for job in f.elements('/company/job-offers/job-offer')] | |
29 | ||
30 | self.employees = [{ | |
31 | 'country': {'name': emp.text('country/name'), 'id': emp.int('country/id'), 'code': emp.text('country/code')}, | |
32 | 'id': emp.int('id'), 'name': emp.text('name')} | |
33 | for emp in f.elements('/company/employees/employee')] | |
34 |