Fixed promo reporting

This commit is contained in:
KEriks 2021-08-30 16:36:25 +03:00
parent dfa6f7e0be
commit 2288fe01ea
2 changed files with 15 additions and 6 deletions

View File

@ -180,12 +180,21 @@ class BaseCitizen(access_points.CitizenAPI):
ugly_js_match = re.search(r'"promotions":\s*(\[{?.*?}?])', html)
ugly_js = ugly_js_match.group(1) if ugly_js_match else "null"
promos = utils.json_loads(utils.normalize_html_json(ugly_js))
self.promos = {}
if self.promos:
self.promos = {k: v for k, v in self.promos.items() if v > self.now}
else:
self.promos = {}
try:
if promos:
self.promos = {p['typeId']: p for p in promos}
except:
pass
for promo in promos:
kind = promo["typeId"]
time_until = utils.localize_timestamp(promo["expiresAt"])
if kind not in self.promos:
self.reporter.report_promo(kind, time_until)
self.promos[kind] = time_until
except Exception:
self.process_error()
new_date = re.search(r"var new_date = '(\d*)';", html)
if new_date:
self.energy.set_reference_time(utils.good_timedelta(self.now, timedelta(seconds=int(new_date.group(1)))))

View File

@ -3,10 +3,10 @@
"""Tests for `erepublik` package."""
from erepublik import Citizen
import unittest
from erepublik import Citizen
class TestErepublik(unittest.TestCase):
"""Tests for `erepublik` package."""