Moved utils.report_promo to classes.Reporter.report_promo

This commit is contained in:
Eriks Karls 2020-04-23 14:39:42 +03:00
parent 1bbe72f3e1
commit 904fd4efc8
4 changed files with 7 additions and 8 deletions

View File

@ -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

View File

@ -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)

View File

@ -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):

View File

@ -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