Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
c874247335 | |||
6e9def4394 | |||
d6fbaa7945 | |||
eb740c60c7 | |||
240c409739 | |||
f348a315c5 | |||
7a09eea2b4 | |||
81b1069cf0 | |||
429d43df15 | |||
c81986d65e | |||
7bb988f716 | |||
16cae24712 | |||
3e051fe906 | |||
aa9cda9314 | |||
fc66db8cab | |||
6bbc4f8768 | |||
160b32a914 | |||
a51c3c620e | |||
a1c26468eb | |||
4895ae3663 | |||
b8d7cc8d7c | |||
1d0645b490 | |||
30cf6203b7 | |||
a32e88218d | |||
a031da0ee7 | |||
bdb13fa4ae | |||
e1e3b33d46 | |||
e09ca143b1 | |||
61d0599295 | |||
1ef600492a | |||
377eda6445 |
18
HISTORY.rst
18
HISTORY.rst
@ -2,6 +2,24 @@
|
|||||||
History
|
History
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
0.22.3 (2020-11-16)
|
||||||
|
-------------------
|
||||||
|
* Fixed round to even bug when doing wam and not enough raw.
|
||||||
|
* Added meta industry airplaneRaw
|
||||||
|
* Added method `Citizen.buy_market_offer(OfferItem, amount=None)` to directly buy market offer with included travel to country and back.
|
||||||
|
|
||||||
|
0.22.2 (2020-11-09)
|
||||||
|
-------------------
|
||||||
|
* Allow querying market offers for q2-q5 aircrafts
|
||||||
|
* Added "Ticket" industry
|
||||||
|
|
||||||
|
0.22.1 (2020-11-04)
|
||||||
|
-------------------
|
||||||
|
* Requirement update
|
||||||
|
* Unified product naming in inventory and other places based on `erepublik.constants.INDUSTRIES` values
|
||||||
|
* `erepublik.Citizen` parameter `auto_login` now defaults to `False`
|
||||||
|
* Continued work on more verbose action and result logging
|
||||||
|
|
||||||
0.22.0 (2020-10-22)
|
0.22.0 (2020-10-22)
|
||||||
-------------------
|
-------------------
|
||||||
* Ability to dump session and restore from file
|
* Ability to dump session and restore from file
|
||||||
|
@ -93,8 +93,8 @@
|
|||||||
<label class="custom-control-label" for="wam">Work as manager</label>
|
<label class="custom-control-label" for="wam">Work as manager</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="custom-control custom-switch">
|
<div class="custom-control custom-switch">
|
||||||
<input type="checkbox" class="custom-control-input" onchange="updateJson()" id="employ">
|
<input type="checkbox" class="custom-control-input" onchange="updateJson()" id="employees">
|
||||||
<label class="custom-control-label" for="employ">Employ employees</label>
|
<label class="custom-control-label" for="employees">Employ employees</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="custom-control custom-switch">
|
<div class="custom-control custom-switch">
|
||||||
<input type="checkbox" class="custom-control-input" onchange="updateJson()" id="auto_buy_raw" checked>
|
<input type="checkbox" class="custom-control-input" onchange="updateJson()" id="auto_buy_raw" checked>
|
||||||
@ -236,8 +236,8 @@
|
|||||||
config.debug = debug.checked;
|
config.debug = debug.checked;
|
||||||
let wam = document.getElementById('wam'); // Generated
|
let wam = document.getElementById('wam'); // Generated
|
||||||
config.wam = wam.checked;
|
config.wam = wam.checked;
|
||||||
let employ = document.getElementById('employ'); // Generated
|
let employees = document.getElementById('employees'); // Generated
|
||||||
config.employ = employ.checked;
|
config.employees = employees.checked;
|
||||||
|
|
||||||
let auto_buy_raw = document.getElementById('auto_buy_raw'); // Generated
|
let auto_buy_raw = document.getElementById('auto_buy_raw'); // Generated
|
||||||
let auto_sell_all = document.getElementById('auto_sell_all'); // Generated
|
let auto_sell_all = document.getElementById('auto_sell_all'); // Generated
|
||||||
@ -249,7 +249,7 @@
|
|||||||
let auto_sell_house = document.getElementById('auto_sell_house'); // Generated
|
let auto_sell_house = document.getElementById('auto_sell_house'); // Generated
|
||||||
let auto_sell_arm = document.getElementById('auto_sell_arm'); // Generated
|
let auto_sell_arm = document.getElementById('auto_sell_arm'); // Generated
|
||||||
let auto_sell_air = document.getElementById('auto_sell_air'); // Generated
|
let auto_sell_air = document.getElementById('auto_sell_air'); // Generated
|
||||||
if (config.wam || config.employ) {
|
if (config.wam || config.employees) {
|
||||||
auto_buy_raw.disabled = false;
|
auto_buy_raw.disabled = false;
|
||||||
auto_sell_all.disabled = false;
|
auto_sell_all.disabled = false;
|
||||||
auto_sell_frm.disabled = false;
|
auto_sell_frm.disabled = false;
|
||||||
@ -359,7 +359,7 @@
|
|||||||
"interactive": true,
|
"interactive": true,
|
||||||
"debug": true,
|
"debug": true,
|
||||||
"wam": true,
|
"wam": true,
|
||||||
"employ": true,
|
"employees": true,
|
||||||
"auto_buy_raw": true,
|
"auto_buy_raw": true,
|
||||||
"auto_sell_all": true,
|
"auto_sell_all": true,
|
||||||
"auto_sell": [
|
"auto_sell": [
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
__author__ = """Eriks Karls"""
|
__author__ = """Eriks Karls"""
|
||||||
__email__ = 'eriks@72.lv'
|
__email__ = 'eriks@72.lv'
|
||||||
__version__ = '0.22.1.3'
|
__version__ = '0.23.0'
|
||||||
|
|
||||||
from erepublik import classes, utils, constants
|
from erepublik import classes, utils, constants
|
||||||
from erepublik.citizen import Citizen
|
from erepublik.citizen import Citizen
|
||||||
|
@ -15,9 +15,11 @@ class SlowRequests(Session):
|
|||||||
timeout: datetime.timedelta = datetime.timedelta(milliseconds=500)
|
timeout: datetime.timedelta = datetime.timedelta(milliseconds=500)
|
||||||
uas: List[str] = [
|
uas: List[str] = [
|
||||||
# Chrome
|
# Chrome
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36', # noqa
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36', # noqa
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36', # noqa
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', # noqa
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', # noqa
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36', # noqa
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36', # noqa
|
||||||
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36',
|
||||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36',
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36',
|
||||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
|
||||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36',
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36',
|
||||||
@ -159,8 +161,10 @@ class ErepublikAnniversaryAPI(CitizenBaseAPI):
|
|||||||
data = {'nodeId': node_id, '_token': self.token, "currencyCost": currency_amount}
|
data = {'nodeId': node_id, '_token': self.token, "currencyCost": currency_amount}
|
||||||
return self.post(f"{self.url}/main/map-rewards-speedup", data=data)
|
return self.post(f"{self.url}/main/map-rewards-speedup", data=data)
|
||||||
|
|
||||||
def _post_map_rewards_claim(self, node_id: int) -> Response:
|
def _post_map_rewards_claim(self, node_id: int, extra: bool = False) -> Response:
|
||||||
data = {'nodeId': node_id, '_token': self.token}
|
data = {'nodeId': node_id, '_token': self.token}
|
||||||
|
if extra:
|
||||||
|
data['claimExtra'] = 1
|
||||||
return self.post(f"{self.url}/main/map-rewards-claim", data=data)
|
return self.post(f"{self.url}/main/map-rewards-claim", data=data)
|
||||||
|
|
||||||
def _post_main_wheel_of_fortune_spin(self, cost) -> Response:
|
def _post_main_wheel_of_fortune_spin(self, cost) -> Response:
|
||||||
@ -174,6 +178,9 @@ class ErepublikArticleAPI(CitizenBaseAPI):
|
|||||||
def _get_main_article_json(self, article_id: int) -> Response:
|
def _get_main_article_json(self, article_id: int) -> Response:
|
||||||
return self.get(f"{self.url}/main/articleJson/{article_id}")
|
return self.get(f"{self.url}/main/articleJson/{article_id}")
|
||||||
|
|
||||||
|
def _get_main_delete_article(self, article_id: int) -> Response:
|
||||||
|
return self.get(f"{self.url}/main/delete-article/{article_id}/1")
|
||||||
|
|
||||||
def _post_main_article_comments(self, article_id: int, page: int = 1) -> Response:
|
def _post_main_article_comments(self, article_id: int, page: int = 1) -> Response:
|
||||||
data = dict(_token=self.token, articleId=article_id, page=page)
|
data = dict(_token=self.token, articleId=article_id, page=page)
|
||||||
if page:
|
if page:
|
||||||
|
@ -12,6 +12,7 @@ from typing import Any, Dict, List, NoReturn, Optional, Set, Tuple, Union
|
|||||||
from requests import HTTPError, RequestException, Response
|
from requests import HTTPError, RequestException, Response
|
||||||
|
|
||||||
from . import utils, classes, access_points, constants
|
from . import utils, classes, access_points, constants
|
||||||
|
from .classes import OfferItem
|
||||||
|
|
||||||
|
|
||||||
class BaseCitizen(access_points.CitizenAPI):
|
class BaseCitizen(access_points.CitizenAPI):
|
||||||
@ -348,7 +349,7 @@ class BaseCitizen(access_points.CitizenAPI):
|
|||||||
_item_data = dict(kind=kind, quality=item_data.get('quality', 0), amount=item_data.get('amount', 0),
|
_item_data = dict(kind=kind, quality=item_data.get('quality', 0), amount=item_data.get('amount', 0),
|
||||||
durability=item_data.get('duration', 0), icon=icon, name=name)
|
durability=item_data.get('duration', 0), icon=icon, name=name)
|
||||||
if item_data.get('type') in ('damageBoosters', "aircraftDamageBoosters"):
|
if item_data.get('type') in ('damageBoosters', "aircraftDamageBoosters"):
|
||||||
_item_data = {_item_data['durability']: item_data}
|
_item_data = {_item_data['durability']: _item_data}
|
||||||
else:
|
else:
|
||||||
if item_data.get('type') == 'bomb':
|
if item_data.get('type') == 'bomb':
|
||||||
firepower = 0
|
firepower = 0
|
||||||
@ -688,9 +689,15 @@ class BaseCitizen(access_points.CitizenAPI):
|
|||||||
if re.search(r'Occasionally there are a couple of things which we need to check or to implement in order make '
|
if re.search(r'Occasionally there are a couple of things which we need to check or to implement in order make '
|
||||||
r'your experience in eRepublik more pleasant. <strong>Don\'t worry about ongoing battles, timer '
|
r'your experience in eRepublik more pleasant. <strong>Don\'t worry about ongoing battles, timer '
|
||||||
r'will be stopped during maintenance.</strong>', response.text):
|
r'will be stopped during maintenance.</strong>', response.text):
|
||||||
self.write_log("eRepublik ss having maintenance. Sleeping for 5 minutes")
|
self.write_log("eRepublik is having maintenance. Sleeping for 5 minutes")
|
||||||
self.sleep(5 * 60)
|
self.sleep(5 * 60)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if re.search('We are experiencing some tehnical dificulties', response.text):
|
||||||
|
self.write_log("eRepublik is having technical difficulties. Sleeping for 5 minutes")
|
||||||
|
self.sleep(5 * 60)
|
||||||
|
return True
|
||||||
|
|
||||||
return bool(re.search(r'body id="error"|Internal Server Error|'
|
return bool(re.search(r'body id="error"|Internal Server Error|'
|
||||||
r'CSRF attack detected|meta http-equiv="refresh"|'
|
r'CSRF attack detected|meta http-equiv="refresh"|'
|
||||||
r'not_authenticated', response.text))
|
r'not_authenticated', response.text))
|
||||||
@ -724,8 +731,8 @@ class CitizenAnniversary(BaseCitizen):
|
|||||||
def start_unlocking_map_quest_node(self, node_id: int):
|
def start_unlocking_map_quest_node(self, node_id: int):
|
||||||
return self._post_map_rewards_unlock(node_id)
|
return self._post_map_rewards_unlock(node_id)
|
||||||
|
|
||||||
def collect_map_quest_node(self, node_id: int):
|
def collect_map_quest_node(self, node_id: int, extra: bool = False):
|
||||||
return self._post_map_rewards_claim(node_id)
|
return self._post_map_rewards_claim(node_id, extra)
|
||||||
|
|
||||||
def speedup_map_quest_node(self, node_id: int):
|
def speedup_map_quest_node(self, node_id: int):
|
||||||
node = self.get_anniversary_quest_data().get('cities', {}).get(str(node_id), {})
|
node = self.get_anniversary_quest_data().get('cities', {}).get(str(node_id), {})
|
||||||
@ -801,7 +808,14 @@ class CitizenTravel(BaseCitizen):
|
|||||||
if data.get('alreadyInRegion'):
|
if data.get('alreadyInRegion'):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
country = constants.COUNTRIES[data.get('preselectCountryId')]
|
country = None
|
||||||
|
for country_data in data.get('countries').values():
|
||||||
|
if region_id in country_data.get('regions'):
|
||||||
|
country = constants.COUNTRIES[country_data.get('id')]
|
||||||
|
break
|
||||||
|
|
||||||
|
if country is None:
|
||||||
|
raise classes.ErepublikException('Region not found!')
|
||||||
|
|
||||||
if self._travel(country, region_id):
|
if self._travel(country, region_id):
|
||||||
self._report_action("TRAVEL", "Traveled to region")
|
self._report_action("TRAVEL", "Traveled to region")
|
||||||
@ -983,7 +997,7 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
def check_house_durability(self) -> Dict[int, datetime]:
|
def check_house_durability(self) -> Dict[int, datetime]:
|
||||||
ret = {}
|
ret = {}
|
||||||
inv = self.get_inventory()
|
inv = self.get_inventory()
|
||||||
for house_quality, active_house in inv['active'].get('house', {}).items():
|
for house_quality, active_house in inv['active'].get('House', {}).items():
|
||||||
till = utils.good_timedelta(self.now, timedelta(seconds=active_house['time_left']))
|
till = utils.good_timedelta(self.now, timedelta(seconds=active_house['time_left']))
|
||||||
ret.update({house_quality: till})
|
ret.update({house_quality: till})
|
||||||
return ret
|
return ret
|
||||||
@ -996,10 +1010,10 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
countries = [self.details.citizenship, ]
|
countries = [self.details.citizenship, ]
|
||||||
if self.details.current_country != self.details.citizenship:
|
if self.details.current_country != self.details.citizenship:
|
||||||
countries.append(self.details.current_country)
|
countries.append(self.details.current_country)
|
||||||
offers = [self.get_market_offers("house", q, country)[f"q{q}"] for country in countries]
|
offers = [self.get_market_offers("House", q, country)[f"q{q}"] for country in countries]
|
||||||
local_cheapest = sorted(offers, key=lambda o: o.price)[0]
|
local_cheapest = sorted(offers, key=lambda o: o.price)[0]
|
||||||
|
|
||||||
global_cheapest = self.get_market_offers("house", q)[f"q{q}"]
|
global_cheapest = self.get_market_offers("House", q)[f"q{q}"]
|
||||||
if global_cheapest.price + 200 < local_cheapest.price:
|
if global_cheapest.price + 200 < local_cheapest.price:
|
||||||
if self.travel_to_country(global_cheapest.country):
|
if self.travel_to_country(global_cheapest.country):
|
||||||
buy = self.buy_from_market(global_cheapest.offer_id, 1)
|
buy = self.buy_from_market(global_cheapest.offer_id, 1)
|
||||||
@ -1036,7 +1050,7 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
r: Dict[str, Any] = self._post_economy_activate_house(quality).json()
|
r: Dict[str, Any] = self._post_economy_activate_house(quality).json()
|
||||||
self._update_inventory_data(r)
|
self._update_inventory_data(r)
|
||||||
if r.get("status") and not r.get("error"):
|
if r.get("status") and not r.get("error"):
|
||||||
house: Dict[str, Union[int, str]] = self.get_inventory()['active']['house'][quality]
|
house: Dict[str, Union[int, str]] = self.get_inventory()['active']['House'][quality]
|
||||||
time_left = timedelta(seconds=house["time_left"])
|
time_left = timedelta(seconds=house["time_left"])
|
||||||
active_until = utils.good_timedelta(self.now, time_left)
|
active_until = utils.good_timedelta(self.now, time_left)
|
||||||
self._report_action(
|
self._report_action(
|
||||||
@ -1113,14 +1127,16 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
if not constants.INDUSTRIES[industry]:
|
if not constants.INDUSTRIES[industry]:
|
||||||
self.write_log(f"Trying to sell unsupported industry {industry}")
|
self.write_log(f"Trying to sell unsupported industry {industry}")
|
||||||
|
|
||||||
final = industry in [1, 2, 4, 23]
|
_inv_qlt = quality if industry in [1, 2, 3, 4, 23] else 0
|
||||||
items = self.inventory['final' if final else 'raw'][constants.INDUSTRIES[industry]]
|
_kind = 'final' if industry in [1, 2, 4, 4, 23] else 'raw'
|
||||||
if items[quality if final else 0]['amount'] < amount:
|
inventory = self.get_inventory()
|
||||||
self.update_inventory()
|
items = inventory[_kind].get(constants.INDUSTRIES[industry], {_inv_qlt: {'amount': 0}})
|
||||||
items = self.inventory['final' if final else 'raw'][constants.INDUSTRIES[industry]]
|
if items[_inv_qlt]['amount'] < amount:
|
||||||
if items[quality if final else 0]['amount'] < amount:
|
inventory = self.get_inventory(True)
|
||||||
|
items = inventory[_kind].get(constants.INDUSTRIES[industry], {_inv_qlt: {'amount': 0}})
|
||||||
|
if items[_inv_qlt]['amount'] < amount:
|
||||||
self._report_action("ECONOMY_SELL_PRODUCTS", "Unable to sell! Not enough items in storage!",
|
self._report_action("ECONOMY_SELL_PRODUCTS", "Unable to sell! Not enough items in storage!",
|
||||||
kwargs=dict(inventory=items[quality if final else 0], amount=amount))
|
kwargs=dict(inventory=items[_inv_qlt], amount=amount))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
@ -1140,20 +1156,37 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
def buy_from_market(self, offer: int, amount: int) -> dict:
|
def buy_from_market(self, offer: int, amount: int) -> dict:
|
||||||
ret = self._post_economy_marketplace_actions('buy', offer=offer, amount=amount)
|
ret = self._post_economy_marketplace_actions('buy', offer=offer, amount=amount)
|
||||||
json_ret = ret.json()
|
json_ret = ret.json()
|
||||||
if json_ret.get('error'):
|
if not json_ret.get('error', True):
|
||||||
return json_ret
|
|
||||||
else:
|
|
||||||
self.details.cc = ret.json()['currency']
|
self.details.cc = ret.json()['currency']
|
||||||
self.details.gold = ret.json()['gold']
|
self.details.gold = ret.json()['gold']
|
||||||
json_ret.pop("offerUpdate", None)
|
json_ret.pop("offerUpdate", None)
|
||||||
self._report_action("BOUGHT_PRODUCTS", "", kwargs=json_ret)
|
self._report_action("BOUGHT_PRODUCTS", json_ret.get('message'), kwargs=json_ret)
|
||||||
|
return json_ret
|
||||||
|
|
||||||
|
def buy_market_offer(self, offer: OfferItem, amount: int = None) -> dict:
|
||||||
|
if amount is None or amount > offer.amount:
|
||||||
|
amount = offer.amount
|
||||||
|
traveled = False
|
||||||
|
if not self.details.current_country == offer.country:
|
||||||
|
traveled = True
|
||||||
|
self.travel_to_country(offer.country)
|
||||||
|
ret = self._post_economy_marketplace_actions('buy', offer=offer.offer_id, amount=amount)
|
||||||
|
json_ret = ret.json()
|
||||||
|
if not json_ret.get('error', True):
|
||||||
|
self.details.cc = ret.json()['currency']
|
||||||
|
self.details.gold = ret.json()['gold']
|
||||||
|
json_ret.pop("offerUpdate", None)
|
||||||
|
self._report_action("BOUGHT_PRODUCTS", json_ret.get('message'), kwargs=json_ret)
|
||||||
|
if traveled:
|
||||||
|
self.travel_to_residence()
|
||||||
return json_ret
|
return json_ret
|
||||||
|
|
||||||
def get_market_offers(
|
def get_market_offers(
|
||||||
self, product_name: str, quality: int = None, country: constants.Country = None
|
self, product_name: str, quality: int = None, country: constants.Country = None
|
||||||
) -> Dict[str, classes.OfferItem]:
|
) -> Dict[str, classes.OfferItem]:
|
||||||
raw_short_names = dict(frm="foodRaw", wrm="weaponRaw", hrm="houseRaw", arm="airplaneRaw")
|
raw_short_names = dict(frm="foodRaw", wrm="weaponRaw", hrm="houseRaw", arm="airplaneRaw")
|
||||||
q1_industries = ["aircraft"] + list(raw_short_names.values())
|
q1_industries = list(raw_short_names.values())
|
||||||
|
q5_industries = ['house', 'aircraft', 'ticket']
|
||||||
if product_name in raw_short_names:
|
if product_name in raw_short_names:
|
||||||
quality = 1
|
quality = 1
|
||||||
product_name = raw_short_names[product_name]
|
product_name = raw_short_names[product_name]
|
||||||
@ -1167,7 +1200,7 @@ class CitizenEconomy(CitizenTravel):
|
|||||||
if quality:
|
if quality:
|
||||||
offers[f"q{quality}"] = classes.OfferItem()
|
offers[f"q{quality}"] = classes.OfferItem()
|
||||||
else:
|
else:
|
||||||
max_quality = 1 if product_name in q1_industries else 5 if product_name == 'house' else 7
|
max_quality = 1 if product_name in q1_industries else 5 if product_name.lower() in q5_industries else 7
|
||||||
for q in range(max_quality):
|
for q in range(max_quality):
|
||||||
offers[f"q{q + 1}"] = classes.OfferItem()
|
offers[f"q{q + 1}"] = classes.OfferItem()
|
||||||
|
|
||||||
@ -1411,6 +1444,19 @@ class CitizenMedia(BaseCitizen):
|
|||||||
"\n".join(["{}: {}".format(k, v) for k, v in kinds.items()]), kind
|
"\n".join(["{}: {}".format(k, v) for k, v in kinds.items()]), kind
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def get_article(self, article_id: int) -> Dict[str, Any]:
|
||||||
|
return self._get_main_article_json(article_id).json()
|
||||||
|
|
||||||
|
def delete_article(self, article_id: int) -> NoReturn:
|
||||||
|
article_data = self.get_article(article_id)
|
||||||
|
if article_data and article_data['articleData']['canDelete']:
|
||||||
|
self._report_action("ARTICLE_DELETE",
|
||||||
|
f"Attempting to delete article '{article_data['article']['title']}' (#{article_id})",
|
||||||
|
kwargs=article_data)
|
||||||
|
self._get_main_delete_article(article_id)
|
||||||
|
else:
|
||||||
|
self.write_log(f"Unable to delete article (#{article_id})!")
|
||||||
|
|
||||||
|
|
||||||
class CitizenMilitary(CitizenTravel):
|
class CitizenMilitary(CitizenTravel):
|
||||||
all_battles: Dict[int, classes.Battle] = None
|
all_battles: Dict[int, classes.Battle] = None
|
||||||
@ -1582,6 +1628,7 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
def get_cheap_tp_divisions(self) -> Dict[str, List[Tuple[int, classes.BattleDivision]]]:
|
def get_cheap_tp_divisions(self) -> Dict[str, List[Tuple[int, classes.BattleDivision]]]:
|
||||||
air_divs: List[Tuple[int, classes.BattleDivision]] = []
|
air_divs: List[Tuple[int, classes.BattleDivision]] = []
|
||||||
ground_divs: List[Tuple[int, classes.BattleDivision]] = []
|
ground_divs: List[Tuple[int, classes.BattleDivision]] = []
|
||||||
|
check_maverick = self.maverick and self.config.maverick
|
||||||
for battle in reversed(self.sorted_battles(True, True)):
|
for battle in reversed(self.sorted_battles(True, True)):
|
||||||
for division in battle.div.values():
|
for division in battle.div.values():
|
||||||
is_start_ok = utils.good_timedelta(division.battle.start, timedelta(minutes=-1)) < self.now
|
is_start_ok = utils.good_timedelta(division.battle.start, timedelta(minutes=-1)) < self.now
|
||||||
@ -1594,7 +1641,7 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
else:
|
else:
|
||||||
air_divs.append((medal.get('1').get('raw_value'), division))
|
air_divs.append((medal.get('1').get('raw_value'), division))
|
||||||
elif not division.is_air and self.config.ground:
|
elif not division.is_air and self.config.ground:
|
||||||
if not division.div == self.division and not self.maverick:
|
if not division.div == self.division and not check_maverick:
|
||||||
continue
|
continue
|
||||||
division_medals = self.get_battle_round_data(division)
|
division_medals = self.get_battle_round_data(division)
|
||||||
medal = division_medals[self.details.citizenship == division.battle.defender.country]
|
medal = division_medals[self.details.citizenship == division.battle.defender.country]
|
||||||
@ -1948,13 +1995,8 @@ class CitizenMilitary(CitizenTravel):
|
|||||||
count = self.energy.food_fights
|
count = self.energy.food_fights
|
||||||
msg = "Fighting all-in. Doing %i hits" % count
|
msg = "Fighting all-in. Doing %i hits" % count
|
||||||
|
|
||||||
# All-in for AIR battles
|
|
||||||
elif all([self.config.air, self.config.all_in, self.energy.available >= self.energy.limit]):
|
|
||||||
count = self.energy.food_fights
|
|
||||||
msg = "Fighting all-in in AIR. Doing %i hits" % count
|
|
||||||
|
|
||||||
# Get to next Energy +1
|
# Get to next Energy +1
|
||||||
elif self.next_reachable_energy and self.config.next_energy:
|
elif self.config.next_energy and self.next_reachable_energy:
|
||||||
count = self.next_reachable_energy
|
count = self.next_reachable_energy
|
||||||
msg = "Fighting for +1 energy. Doing %i hits" % count
|
msg = "Fighting for +1 energy. Doing %i hits" % count
|
||||||
|
|
||||||
@ -2195,7 +2237,8 @@ class CitizenTasks(BaseCitizen):
|
|||||||
js = response.json()
|
js = response.json()
|
||||||
good_msg = ["already_worked", "captcha"]
|
good_msg = ["already_worked", "captcha"]
|
||||||
if not js.get("status") and not js.get("message") in good_msg:
|
if not js.get("status") and not js.get("message") in good_msg:
|
||||||
if js.get('message') == 'employee':
|
if js.get('message') in ['employee', 'money']:
|
||||||
|
self.resign_from_employer()
|
||||||
self.find_new_job()
|
self.find_new_job()
|
||||||
self.update_citizen_info()
|
self.update_citizen_info()
|
||||||
self.work()
|
self.work()
|
||||||
@ -2570,7 +2613,11 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
if raw_kind:
|
if raw_kind:
|
||||||
raw_kind = raw_kind.group(1)
|
raw_kind = raw_kind.group(1)
|
||||||
result = response.get("result", {})
|
result = response.get("result", {})
|
||||||
amount_needed = round(result.get("consume", 0) - result.get("stock", 0) + 0.49)
|
amount_needed = round(result.get("consume", 0) - result.get("stock", 0) + 0.5)
|
||||||
|
self._report_action(
|
||||||
|
'WORK_AS_MANAGER', f"Unable to wam! Missing {amount_needed} {raw_kind}, will try to buy.",
|
||||||
|
kwargs=response
|
||||||
|
)
|
||||||
start_place = (self.details.current_country, self.details.current_region)
|
start_place = (self.details.current_country, self.details.current_region)
|
||||||
while amount_needed > 0:
|
while amount_needed > 0:
|
||||||
amount = amount_needed
|
amount = amount_needed
|
||||||
@ -2579,17 +2626,25 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenEconomy, CitizenLeade
|
|||||||
|
|
||||||
if not best_offer.country == self.details.current_country:
|
if not best_offer.country == self.details.current_country:
|
||||||
self.travel_to_country(best_offer.country)
|
self.travel_to_country(best_offer.country)
|
||||||
|
self._report_action("ECONOMY_BUY", f"Attempting to buy {amount} {raw_kind} for {best_offer.price*amount}cc")
|
||||||
rj = self.buy_from_market(amount=amount, offer=best_offer.offer_id)
|
rj = self.buy_from_market(amount=amount, offer=best_offer.offer_id)
|
||||||
if not rj.get('error'):
|
if not rj.get('error'):
|
||||||
amount_needed -= amount
|
amount_needed -= amount
|
||||||
else:
|
else:
|
||||||
self.write_log(rj.get('message', ""))
|
self.write_log(rj.get('message', ""))
|
||||||
|
self._report_action(
|
||||||
|
"ECONOMY_BUY", f"Unable to buy products! Reason: {rj.get('message')}", kwargs=rj
|
||||||
|
)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if not start_place == (self.details.current_country, self.details.current_region):
|
if not start_place == (self.details.current_country, self.details.current_region):
|
||||||
self.travel_to_holding(holding)
|
self.travel_to_holding(holding)
|
||||||
self._wam(holding)
|
self._wam(holding)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not start_place == (self.details.current_country, self.details.current_region):
|
||||||
|
self.travel_to_residence()
|
||||||
|
return
|
||||||
elif response.get("message") == "not_enough_health_food":
|
elif response.get("message") == "not_enough_health_food":
|
||||||
self.buy_food()
|
self.buy_food()
|
||||||
self._wam(holding)
|
self._wam(holding)
|
||||||
|
@ -357,6 +357,7 @@ class Config:
|
|||||||
telegram = True
|
telegram = True
|
||||||
telegram_chat_id = 0
|
telegram_chat_id = 0
|
||||||
telegram_token = ""
|
telegram_token = ""
|
||||||
|
maverick = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.auto_sell = []
|
self.auto_sell = []
|
||||||
@ -389,6 +390,7 @@ class Config:
|
|||||||
self.telegram = True
|
self.telegram = True
|
||||||
self.telegram_chat_id = 0
|
self.telegram_chat_id = 0
|
||||||
self.telegram_token = ""
|
self.telegram_token = ""
|
||||||
|
self.maverick = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
@ -397,7 +399,7 @@ class Config:
|
|||||||
fight=self.fight, air=self.air, ground=self.ground, all_in=self.all_in,
|
fight=self.fight, air=self.air, ground=self.ground, all_in=self.all_in,
|
||||||
next_energy=self.next_energy, boosters=self.boosters, travel_to_fight=self.travel_to_fight,
|
next_energy=self.next_energy, boosters=self.boosters, travel_to_fight=self.travel_to_fight,
|
||||||
always_travel=self.always_travel, epic_hunt=self.epic_hunt, epic_hunt_ebs=self.epic_hunt_ebs,
|
always_travel=self.always_travel, epic_hunt=self.epic_hunt, epic_hunt_ebs=self.epic_hunt_ebs,
|
||||||
rw_def_side=self.rw_def_side, interactive=self.interactive,
|
rw_def_side=self.rw_def_side, interactive=self.interactive, maverick=self.maverick,
|
||||||
continuous_fighting=self.continuous_fighting, auto_buy_raw=self.auto_buy_raw,
|
continuous_fighting=self.continuous_fighting, auto_buy_raw=self.auto_buy_raw,
|
||||||
force_wam=self.force_wam, sort_battles_time=self.sort_battles_time, force_travel=self.force_travel,
|
force_wam=self.force_wam, sort_battles_time=self.sort_battles_time, force_travel=self.force_travel,
|
||||||
telegram=self.telegram, telegram_chat_id=self.telegram_chat_id, telegram_token=self.telegram_token)
|
telegram=self.telegram, telegram_chat_id=self.telegram_chat_id, telegram_token=self.telegram_token)
|
||||||
|
@ -53,14 +53,14 @@ class Country:
|
|||||||
|
|
||||||
|
|
||||||
class Industries:
|
class Industries:
|
||||||
__by_name = {'food': 1, 'weapon': 2, 'house': 4, 'aircraft': 23,
|
__by_name = {'food': 1, 'weapon': 2, 'ticket': 3, 'house': 4, 'aircraft': 23,
|
||||||
'foodraw': 7, 'weaponraw': 12, 'houseraw': 18, 'aircraftraw': 24,
|
'foodraw': 7, 'weaponraw': 12, 'houseraw': 18, 'aircraftraw': 24, 'airplaneraw': 24,
|
||||||
'frm': 7, 'wrm': 12, 'hrm': 18, 'arm': 24,
|
'frm': 7, 'wrm': 12, 'hrm': 18, 'arm': 24,
|
||||||
'frm q1': 7, 'frm q2': 8, 'frm q3': 9, 'frm q4': 10, 'frm q5': 11,
|
'frm q1': 7, 'frm q2': 8, 'frm q3': 9, 'frm q4': 10, 'frm q5': 11,
|
||||||
'wrm q1': 12, 'wrm q2': 13, 'wrm q3': 14, 'wrm q4': 15, 'wrm q5': 16,
|
'wrm q1': 12, 'wrm q2': 13, 'wrm q3': 14, 'wrm q4': 15, 'wrm q5': 16,
|
||||||
'hrm q1': 18, 'hrm q2': 19, 'hrm q3': 20, 'hrm q4': 21, 'hrm q5': 22,
|
'hrm q1': 18, 'hrm q2': 19, 'hrm q3': 20, 'hrm q4': 21, 'hrm q5': 22,
|
||||||
'arm q1': 24, 'arm q2': 25, 'arm q3': 26, 'arm q4': 27, 'arm q5': 28}
|
'arm q1': 24, 'arm q2': 25, 'arm q3': 26, 'arm q4': 27, 'arm q5': 28}
|
||||||
__by_id = {1: "Food", 2: "Weapon", 4: "House", 23: "Aircraft",
|
__by_id = {1: "Food", 2: "Weapon", 3: "Ticket", 4: "House", 23: "Aircraft",
|
||||||
7: "foodRaw", 8: "FRM q2", 9: "FRM q3", 10: "FRM q4", 11: "FRM q5",
|
7: "foodRaw", 8: "FRM q2", 9: "FRM q3", 10: "FRM q4", 11: "FRM q5",
|
||||||
12: "weaponRaw", 13: "WRM q2", 14: "WRM q3", 15: "WRM q4", 16: "WRM q5",
|
12: "weaponRaw", 13: "WRM q2", 14: "WRM q3", 15: "WRM q4", 16: "WRM q5",
|
||||||
17: "houseRaw", 18: "houseRaw", 19: "HRM q2", 20: "HRM q3", 21: "HRM q4", 22: "HRM q5",
|
17: "houseRaw", 18: "houseRaw", 19: "HRM q2", 20: "HRM q3", 21: "HRM q4", 22: "HRM q5",
|
||||||
|
@ -29,7 +29,7 @@ def _battle_launcher(player: Citizen):
|
|||||||
"""
|
"""
|
||||||
global CONFIG
|
global CONFIG
|
||||||
finished_war_ids = {*[]}
|
finished_war_ids = {*[]}
|
||||||
war_data = CONFIG.get('start_battles', {})
|
war_data = CONFIG.get('battle_launcher', {})
|
||||||
war_ids = {int(war_id) for war_id in war_data.keys()}
|
war_ids = {int(war_id) for war_id in war_data.keys()}
|
||||||
next_attack_time = player.now
|
next_attack_time = player.now
|
||||||
next_attack_time = next_attack_time.replace(minute=next_attack_time.minute // 5 * 5, second=0)
|
next_attack_time = next_attack_time.replace(minute=next_attack_time.minute // 5 * 5, second=0)
|
||||||
@ -45,7 +45,7 @@ def _battle_launcher(player: Citizen):
|
|||||||
|
|
||||||
status = player.get_war_status(war_id)
|
status = player.get_war_status(war_id)
|
||||||
if status.get('ended', False):
|
if status.get('ended', False):
|
||||||
CONFIG['start_battles'].pop(war_id, None)
|
CONFIG['battle_launcher'].pop(war_id, None)
|
||||||
finished_war_ids.add(war_id)
|
finished_war_ids.add(war_id)
|
||||||
continue
|
continue
|
||||||
elif not status.get('can_attack'):
|
elif not status.get('can_attack'):
|
||||||
@ -64,7 +64,15 @@ def _battle_launcher(player: Citizen):
|
|||||||
player.update_war_info()
|
player.update_war_info()
|
||||||
battle_id = player.get_war_status(war_id).get("battle_id")
|
battle_id = player.get_war_status(war_id).get("battle_id")
|
||||||
if battle_id is not None and battle_id in player.all_battles:
|
if battle_id is not None and battle_id in player.all_battles:
|
||||||
player.fight(battle_id, player.details.citizenship, hits)
|
battle = player.all_battles.get(battle_id)
|
||||||
|
for division in battle.div.values():
|
||||||
|
if division.div == player.division:
|
||||||
|
div = division
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
player.report_error("Players division not found in the first round!")
|
||||||
|
break
|
||||||
|
player.fight(battle, div, battle.invader, hits)
|
||||||
break
|
break
|
||||||
player.sleep(1)
|
player.sleep(1)
|
||||||
if attacked:
|
if attacked:
|
||||||
|
@ -6,7 +6,11 @@ CONFIG = {
|
|||||||
'email': 'player@email.com',
|
'email': 'player@email.com',
|
||||||
'password': 'Pa$5w0rd!',
|
'password': 'Pa$5w0rd!',
|
||||||
'interactive': True,
|
'interactive': True,
|
||||||
'debug': True
|
'debug': True,
|
||||||
|
'work': True,
|
||||||
|
'ot': True, # Work OverTime
|
||||||
|
'wam': True, # WorkAsManager
|
||||||
|
'train': True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -14,7 +18,10 @@ CONFIG = {
|
|||||||
def main():
|
def main():
|
||||||
player = Citizen(email=CONFIG['email'], password=CONFIG['password'], auto_login=False)
|
player = Citizen(email=CONFIG['email'], password=CONFIG['password'], auto_login=False)
|
||||||
player.config.interactive = CONFIG['interactive']
|
player.config.interactive = CONFIG['interactive']
|
||||||
player.config.fight = CONFIG['fight']
|
player.config.work = CONFIG['work']
|
||||||
|
player.config.train = CONFIG['train']
|
||||||
|
player.config.ot = CONFIG['ot']
|
||||||
|
player.config.wam = CONFIG['wam']
|
||||||
player.set_debug(CONFIG.get('debug', False))
|
player.set_debug(CONFIG.get('debug', False))
|
||||||
player.login()
|
player.login()
|
||||||
now = player.now.replace(second=0, microsecond=0)
|
now = player.now.replace(second=0, microsecond=0)
|
||||||
@ -76,7 +83,7 @@ def main():
|
|||||||
tasks.update({'eat': next_time})
|
tasks.update({'eat': next_time})
|
||||||
|
|
||||||
if tasks.get('ot', dt_max) <= now:
|
if tasks.get('ot', dt_max) <= now:
|
||||||
player.write_log("Doing task: ot")
|
player.write_log("Doing task: work overtime")
|
||||||
if now > player.my_companies.next_ot_time:
|
if now > player.my_companies.next_ot_time:
|
||||||
player.work_ot()
|
player.work_ot()
|
||||||
next_time = now + timedelta(minutes=60)
|
next_time = now + timedelta(minutes=60)
|
||||||
|
@ -2,15 +2,15 @@ bump2version==1.0.1
|
|||||||
coverage==5.3
|
coverage==5.3
|
||||||
edx-sphinx-theme==1.5.0
|
edx-sphinx-theme==1.5.0
|
||||||
flake8==3.8.4
|
flake8==3.8.4
|
||||||
ipython>=7.18.1
|
ipython>=7.19.0
|
||||||
isort==5.6.4
|
isort==5.6.4
|
||||||
pip==20.2.4
|
pip==20.2.4
|
||||||
PyInstaller==4.0
|
PyInstaller==4.0
|
||||||
pytz==2020.1
|
pytz==2020.4
|
||||||
pytest==6.1.1
|
pytest==6.1.2
|
||||||
responses==0.12.0
|
responses==0.12.0
|
||||||
setuptools==50.3.2
|
setuptools==50.3.2
|
||||||
Sphinx==3.2.1
|
Sphinx==3.3.0
|
||||||
requests==2.24.0
|
requests==2.24.0
|
||||||
PySocks==1.7.1
|
PySocks==1.7.1
|
||||||
tox==3.20.1
|
tox==3.20.1
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.22.1.3
|
current_version = 0.23.0
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?
|
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?
|
||||||
|
6
setup.py
6
setup.py
@ -12,7 +12,7 @@ with open('HISTORY.rst') as history_file:
|
|||||||
history = history_file.read()
|
history = history_file.read()
|
||||||
|
|
||||||
requirements = [
|
requirements = [
|
||||||
'pytz==2020.1',
|
'pytz==2020.4',
|
||||||
'requests==2.24.0',
|
'requests==2.24.0',
|
||||||
'PySocks==1.7.1'
|
'PySocks==1.7.1'
|
||||||
]
|
]
|
||||||
@ -20,7 +20,7 @@ requirements = [
|
|||||||
setup_requirements = []
|
setup_requirements = []
|
||||||
|
|
||||||
test_requirements = [
|
test_requirements = [
|
||||||
"pytest==6.1.0",
|
"pytest==6.1.2",
|
||||||
"responses==0.12.0"
|
"responses==0.12.0"
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -50,6 +50,6 @@ setup(
|
|||||||
test_suite='tests',
|
test_suite='tests',
|
||||||
tests_require=test_requirements,
|
tests_require=test_requirements,
|
||||||
url='https://github.com/eeriks/erepublik/',
|
url='https://github.com/eeriks/erepublik/',
|
||||||
version='0.22.1.3',
|
version='0.23.0',
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user