Exemple #1
0
    def __init__(self, battleID):
        super(Battle, self).__init__()
        self.id = str(battleID)
        self.__resource = "battle"
        self.__action = "index"
        self.__params = "battleId=" + self.id
        if not self.id.isdigit():
            raise ValueError(self.id)
        else:
            self.__url = api._construct_url(self.__resource, self.__action, self.__params)
            self.__headers = api._construct_headers(self.__url)
        self.data = api._load(self.__url, self.__headers)

        self.is_resistance = self.data["battle"]["is_resistance"] == "true"

        # Region
        self.region_id = int(self.data["battle"]["region"]["id"])
        self.region_name = self.data["battle"]["region"]["name"]

        # Progress
        self.start = self._format_time(self.data["battle"]["progress"]["started-at"])
        self.end = self._format_time(self.data["battle"]["progress"]["finished-at"])
        self.finish_reason = self.data["battle"]["progress"]["finished-reason"]

        # Defenders
        self.defender_id = int(self.data["battle"]["progress"]["countries"]["victim_country"]["id"])
        self.defender_initials = self.data["battle"]["progress"]["countries"]["victim_country"]["initials"]
        self.defender_allies = {}
        for item in self.data["battle"]["progress"]["countries"]["victim_country"]["allies"]:
            country_name = item["country"]["name"]
            country_id = int(item["country"]["allied_country_id"])
            country_initials = item["country"]["initials"]
            self.defender_allies[country_name] = {"id": country_id,
                                                  "initials": country_initials
            }

        # Invaders
        self.attacker_id = int(self.data["battle"]["progress"]["countries"]["invader_country"]["id"])
        self.attacker_initials = self.data["battle"]["progress"]["countries"]["invader_country"]["initials"]
        self.attacker_allies = {}
        for item in self.data["battle"]["progress"]["countries"]["invader_country"]["allies"]:
            country_name = item["country"]["name"]
            country_id = int(item["country"]["allied_country_id"])
            country_initials = item["country"]["initials"]
            self.attacker_allies[country_name] = {"id": country_id,
                                                  "initials": country_initials
            }
Exemple #2
0
    def __init__(self, regionID, page=1):
        super(Region, self).__init__()
        self.id = str(regionID)
        self.page = str(page)
        self.__resource = "region"
        self.__action = "citizens"
        self.__params = ["regionId=" + self.id, "page=" + self.page]

        if not self.id.isdigit() or not self.page.isdigit():
            raise ValueError
        else:
            self.__url = api._construct_url(self.__resource, self.__action, self.__params)
            self.__headers = api._construct_headers(self.__url)
        self.data = api._load(self.__url, self.__headers)
        if self.data["citizens"] is False:
            self.citizenIDs = None
        else:
            self.citizenIDs = [int(cit_id["citizen_id"]) for cit_id in self.data["citizens"]]
Exemple #3
0
    def __init__(self):
        super(Country, self).__init__()
        self.__resource = "countries"
        self.__action = "index"
        self.__url = api._construct_url(self.__resource, self.__action)
        self.__headers = api._construct_headers(self.__url)
        self.data = api._load(self.__url, self.__headers)
        self.__country_dict=self.data["countries"]["country"]
        self.all_countries = [item["name"] for item in self.__country_dict]

            #self.__construct_all_list(self.data["countries"]["country"])

        self.id=None
        self.name=None
        self.initials=None
        self.color=None
        self.continent_id=None
        self.continent_name=None
        self.capital_region_id=None
        self.capital_region_name=None
Exemple #4
0
    def __get_regions(self):
        if not self.id.isdigit():
            raise ValueError
        else:
            self.__url = api._construct_url(self.__resource, self.__action, self.__params)
            self.__headers = api._construct_headers(self.__url)
        self.data = api._load(self.__url, self.__headers)
        self.__base_url = "http://www.erepublik.com/en/main/region/"
        self.regions = []
        for item in self.data["regions"]["region"]:
            region = self.data["regions"]["region"][item]
            region_object= Region(region["name"], int(region["id"]),
                            int(region["current_owner_country_id"]),
                            int(region["original_owner_country_id"]),
                            self.__base_url + region["permalink"])

            self.regions.append(region_object)
            #self.regions[region["name"]] = {
            #    "id": int(region["id"]),
            #    "owner_id": int(region["current_owner_country_id"]),
            #    "original_owner_id": int(region["original_owner_country_id"]),
            #    "url": self.__base_url + region["permalink"]}

        return self.regions
Exemple #5
0
    def __init__(self, citizenID):
        """
        :param citizenID: String or Integer of citizen ID
        """
        super(Citizen, self).__init__()
        self.id = str(citizenID)
        self.__resource = "citizen"
        self.__action = "profile"
        self.__params = "citizenId=" + self.id
        self.profile_url = "http://www.erepublik.com/en/citizen/profile/" + self.id

        if not self.id.isdigit():
            raise ValueError
        else:
            self.__url = api._construct_url(self.__resource,
                                            self.__action,
                                            self.__params)
            self.__headers = api._construct_headers(self.__url)
        self.data = api._load(self.__url, self.__headers)

        # General attributes
        self.name = self.data["general"]["name"]
        if self.name is None:
            raise ValueError
        self.is_alive = self.data["general"]["is_alive"] == "1"
        self.has_avatar = self.data["general"]["has_avatar"]
        self.avatar = self.data["general"]["avatar"]
        self.experience_points = int(self.data["general"]["experience_points"])
        self.level = int(self.data["general"]["level"])
        self.birthday = self.data["general"]["birthDay"]
        self.national_rank = self.data["general"]["nationalRank"]

        # Military attributes
        self.strength = float(self.data["militaryAttributes"]["strength"])
        self.rank_points = int(self.data["militaryAttributes"]["rank_points"])
        self.rank_name = self.data["militaryAttributes"]["rank_name"]
        self.rank_stars = self.data["militaryAttributes"]["rank_stars"]
        self.rank_icon = self.data["militaryAttributes"]["rank_icon"]
        self.rank_value = self.__return_rank_value()

        # Achievements - dict
        if self.data["achievements"]:
            self.achievements = self.__parse_achievements()
        else:
            self.achievements = {}

        # Location
        self.citizenship_country_id = \
            int(self.data["location"]["citizenship_country_id"])
        self.citizenship_country_name = \
            self.data["location"]["citizenship_country_id"]
        self.citizenship_country_initials = \
            self.data["location"]["citizenship_country_initials"]
        self.citizenship_region_id = \
            int(self.data["location"]["citizenship_region_id"])
        self.citizenship_region_name = \
            self.data["location"]["citizenship_region_name"]
        self.residence_country_id = \
            int(self.data["location"]["residence_country_id"])
        self.residence_country_name = \
            self.data["location"]["residence_country_name"]
        self.residence_country_initials = \
            self.data["location"]["residence_country_initials"]
        self.residence_region_id = \
            int(self.data["location"]["residence_region_id"])
        self.residence_region_name = \
            self.data["location"]["residence_region_name"]

        # Party info
        if self.data["party"]:
            self.party_member = True
            self.party_id = int(self.data["party"]["id"])
            self.party_name = self.data["party"]["name"]
            self.is_president = self.data["party"]["is_president"] == "1"
        else:
            self.party_member = False

        # Military unit
        if self.data["militaryUnit"]:
            self.in_unit = True
            self.unit_id = int(self.data["militaryUnit"]["id"])
            self.unit_name = self.data["militaryUnit"]["name"]
            self.unit_leader = self.data["militaryUnit"]["is_leader"]
        else:
            self.in_unit = False

        # Newspappers
        if self.data["newspaper"]:
            self.owns_newspaper = True
            self.newspaper_id = int(self.data["newspaper"]["id"])
            self.newspaper_name = self.data["newspaper"]["name"]
        else:
            self.owns_newspaper = False