Database changes, new translations #32

Merged
profitroll merged 50 commits from dev into main 2023-11-05 15:37:22 +02:00
2 changed files with 25 additions and 5 deletions
Showing only changes of commit 842218859c - Show all commits

View File

@ -1,6 +1,7 @@
import logging
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from bson import json_util
from libbot.pyrogram.classes import PyroClient
from classes.enums import GarbageType
@ -15,11 +16,21 @@ logger = logging.getLogger(__name__)
async def remind(app: PyroClient) -> None:
utcnow = datetime.utcnow()
logger.debug("Performing reminder lookup for %s (UTCNOW)", utcnow)
users = await col_users.find(
{"time_hour": utcnow.hour, "time_minute": utcnow.minute}
).to_list()
logger.debug(
"Found following reminders for %s (UTC NOW): %s",
utcnow,
json_util.dumps(users, indent=None),
)
for user_db in users:
logger.debug("Processing user %s...", json_util.dumps(user_db, indent=None))
user = await PyroUser.from_dict(**user_db)
if not user.enabled or user.location is None:
@ -31,20 +42,26 @@ async def remind(app: PyroClient) -> None:
continue
user_date = from_utc(
datetime(1970, 1, 1, user.time_hour, user.time_minute),
datetime.utcnow() + timedelta(days=user.offset),
user.location.timezone.zone,
)
).replace(hour=0, minute=0, second=0, microsecond=0)
entries = await col_entries.find(
{
"locations": location.id,
"date": user_date.replace(hour=0, minute=0),
"date": user_date,
}
).to_list()
logger.info("Entries of %s for %s: %s", user.id, user_date, entries)
for entry in entries:
logger.debug(
"Sending %s notification about %s",
user.id,
json_util.dumps(entry, indent=None),
)
try:
garbage_type = app._(
str(GarbageType(entry["garbage_type"]).value),

View File

@ -55,9 +55,12 @@ async def command_set_time(app: PyroClient, message: Message):
break
now = datetime.now()
parsed_time = datetime.strptime(answer.text, "%H:%M").replace(
year=1970, month=1, day=1, second=0, microsecond=0
year=now.year, month=now.month, day=now.day, second=0, microsecond=0
)
user_time = to_utc(parsed_time, user.location.timezone.zone)
await user.update_time(hour=user_time.hour, minute=user_time.minute)