Compare commits

...

6 Commits

Author SHA1 Message Date
ef23b3b8db Bump version: 0.20.3.2 → 0.20.3.3 2020-07-09 08:34:41 +03:00
cd861ea29b bugfix 2020-07-09 08:34:38 +03:00
5b580f7c79 Bump version: 0.20.3.1 → 0.20.3.2 2020-07-09 08:27:55 +03:00
0061503581 passed int instead of Country to travel 2020-07-09 08:27:48 +03:00
c78dbae925 Merge branch 'master' of github.com:eeriks/erepublik 2020-07-09 08:25:10 +03:00
6a9b574454 class serialization 2020-07-09 08:09:58 +03:00
5 changed files with 37 additions and 11 deletions

View File

@ -4,8 +4,8 @@
__author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv'
__version__ = '0.20.3.1'
__commit_id__ = "7fa02be"
__version__ = '0.20.3.3'
__commit_id__ = "cd861ea"
from erepublik import classes, utils
from erepublik.citizen import Citizen

View File

@ -763,9 +763,10 @@ class CitizenTravel(BaseCitizen):
if data.get('alreadyInRegion'):
return True
else:
r_json = self._travel(data.get('preselectCountryId'), region_id).json()
country = COUNTRIES[data.get('preselectCountryId')]
r_json = self._travel(country, region_id).json()
if r_json.get('message', '') == 'success':
self._update_citizen_location(data.get('preselectCountryId'), region_id)
self._update_citizen_location(country, region_id)
self._report_action("TRAVEL", "Traveled to region", response=r_json)
return True
return False
@ -792,9 +793,11 @@ class CitizenTravel(BaseCitizen):
if data.get('alreadyInRegion'):
return True
else:
r_json = self._travel(data.get('preselectCountryId'), data.get('preselectRegionId')).json()
country = COUNTRIES[data.get('preselectCountryId')]
region_id = data.get('preselectRegionId')
r_json = self._travel(country, region_id).json()
if r_json.get('message', '') == 'success':
self._update_citizen_location(data.get('preselectCountryId'), data.get('preselectRegionId'))
self._update_citizen_location(country, region_id)
self._report_action("TRAVEL", f"Traveled to holding {holding}", response=r_json)
return True
return False

View File

@ -49,6 +49,10 @@ class Country:
except ValueError:
return self == other
@property
def __dict__(self):
return dict(id=self.id, name=self.name, iso=self.iso)
class ErepublikException(Exception):
def __init__(self, message):
@ -271,7 +275,8 @@ class MyCompanies:
"""
for holding in holdings.values():
if holding.get('id') not in self.holdings:
self.holdings.update({int(holding.get('id')): Holding(holding['id'], holding['region_id'], self.citizen)})
self.holdings.update(
{int(holding.get('id')): Holding(holding['id'], holding['region_id'], self.citizen)})
if not self.holdings.get(0):
self.holdings.update({0: Holding(0, 0, self.citizen)}) # unassigned
@ -612,7 +617,8 @@ class Reporter:
def fetch_battle_priorities(self, country: Country) -> List["Battle"]:
try:
battle_response = self._req.get(f'{self.url}/api/v1/battles/{country.id}')
return [self.citizen.all_battles[bid] for bid in battle_response.json().get('battle_ids', []) if bid in self.citizen.all_battles]
return [self.citizen.all_battles[bid] for bid in battle_response.json().get('battle_ids', []) if
bid in self.citizen.all_battles]
except: # noqa
return []
@ -660,7 +666,8 @@ class BattleSide:
country: Country
defender: bool
def __init__(self, battle: "Battle", country: Country, points: int, allies: List[Country], deployed: List[Country], defender: bool):
def __init__(self, battle: "Battle", country: Country, points: int, allies: List[Country], deployed: List[Country],
defender: bool):
self.battle = battle
self.country = country
self.points = points
@ -683,6 +690,11 @@ class BattleSide:
def __format__(self, format_spec):
return self.country.iso
@property
def __dict__(self):
return dict(points=self.points, country=self.country, defender=self.defender, allies=self.allies,
deployed=self.deployed, battle=repr(self.battle))
class BattleDivision:
id: int
@ -696,6 +708,11 @@ class BattleDivision:
div: int
battle: "Battle"
@property
def __dict__(self):
return dict(id=self.id, division=self.div, terrain=(self.terrain, self.terrain_display), wall=self.wall,
dom_pts=self.dom_pts, epic=self.epic, battle=str(self.battle), end=self.div_end)
@property
def is_air(self):
return self.div == 11
@ -753,6 +770,12 @@ class Battle:
region_id: int
region_name: str
@property
def __dict__(self):
return dict(id=self.id, war_id=self.war_id, divisions=self.div, zone=self.zone_id, rw=self.is_rw,
dict_lib=self.is_dict_lib, start=self.start, sides={'inv': self.invader, 'def': self.defender},
region=[self.region_id, self.region_name])
@property
def has_air(self) -> bool:
for div in self.div.values():

View File

@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.20.3.1
current_version = 0.20.3.3
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?

View File

@ -43,6 +43,6 @@ setup(
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/eeriks/erepublik/',
version='0.20.3.1',
version='0.20.3.3',
zip_safe=False,
)