From 904fd4efc827f58015f104dfc55b024a60651a30 Mon Sep 17 00:00:00 2001 From: Eriks Karls Date: Thu, 23 Apr 2020 14:39:42 +0300 Subject: [PATCH] Moved utils.report_promo to classes.Reporter.report_promo --- erepublik/__init__.py | 2 +- erepublik/citizen.py | 2 +- erepublik/classes.py | 3 +++ erepublik/utils.py | 8 ++------ 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/erepublik/__init__.py b/erepublik/__init__.py index 84dacd2..ab7b3b4 100644 --- a/erepublik/__init__.py +++ b/erepublik/__init__.py @@ -5,7 +5,7 @@ __author__ = """Eriks Karls""" __email__ = 'eriks@72.lv' __version__ = '0.20.0' -__commit_id__ = "2aa1cbd" +__commit_id__ = "1bbe72f" from erepublik import classes, utils from erepublik.citizen import Citizen diff --git a/erepublik/citizen.py b/erepublik/citizen.py index 44b86e1..b472ad9 100644 --- a/erepublik/citizen.py +++ b/erepublik/citizen.py @@ -180,7 +180,7 @@ class BaseCitizen(CitizenAPI): active_promos = [] for kind, time_until in self.promos.items(): active_promos.append(f"{kind} active until {time_until}") - utils.report_promo(kind, time_until) + self.reporter.report_promo(kind, time_until) utils.send_email(self.name, active_promos, player=self, promo=True) new_date = re.search(r"var new_date = '(\d*)';", html) diff --git a/erepublik/classes.py b/erepublik/classes.py index 2c96256..531c8a2 100644 --- a/erepublik/classes.py +++ b/erepublik/classes.py @@ -467,6 +467,9 @@ class Reporter: else: self.__to_update.append(json_data) + def report_promo(self, kind: str, time_untill: datetime.datetime): + self._req.post(f"{self.url}/promos/add/", data=dict(kind=kind, time_untill=time_untill)) + class MyJSONEncoder(json.JSONEncoder): def default(self, o): diff --git a/erepublik/utils.py b/erepublik/utils.py index 0b7f725..3266a85 100644 --- a/erepublik/utils.py +++ b/erepublik/utils.py @@ -9,7 +9,7 @@ import traceback import unicodedata from decimal import Decimal from pathlib import Path -from typing import Any, List, Mapping, NoReturn, Optional, Union +from typing import Any, List, Mapping, Optional, Union import pytz import requests @@ -25,7 +25,7 @@ __all__ = ["FOOD_ENERGY", "COMMIT_ID", "COUNTRIES", "erep_tz", 'COUNTRY_LINK', "now", "localize_dt", "localize_timestamp", "good_timedelta", "eday_from_date", "date_from_eday", "get_sleep_seconds", "interactive_sleep", "silent_sleep", "write_silent_log", "write_interactive_log", "get_file", "write_file", - "send_email", "normalize_html_json", "process_error", "process_warning", 'report_promo', 'calculate_hit'] + "send_email", "normalize_html_json", "process_error", "process_warning", 'calculate_hit'] if not sys.version_info >= (3, 7): raise AssertionError('This script requires Python version 3.7 and higher\n' @@ -395,10 +395,6 @@ def process_warning(log_info: str, name: str, exc_info: tuple, citizen=None, com send_email(name, content, citizen, local_vars=trace) -def report_promo(kind: str, time_untill: datetime.datetime) -> NoReturn: - requests.post('https://api.erep.lv/promos/add/', data=dict(kind=kind, time_untill=time_untill)) - - def slugify(value, allow_unicode=False) -> str: """ Function copied from Django2.2.1 django.utils.text.slugify