Skip to content

Commit

Permalink
Throw away import code
Browse files Browse the repository at this point in the history
  • Loading branch information
BjoernPetersen committed Dec 15, 2024
1 parent d899632 commit ed7ac89
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 174 deletions.
9 changes: 0 additions & 9 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,3 @@ crons:
- schedule: "0 0 * * *"
command: close-polls
suspend: true
- schedule: "0 0 * * *"
command: import-users
suspend: true
- schedule: "0 0 * * *"
command: import-user-groups
suspend: true
- schedule: "0 0 * * *"
command: import-results
suspend: true
69 changes: 0 additions & 69 deletions src/bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import asyncio
import logging
import sys
from dataclasses import replace
from datetime import UTC, datetime, time, timedelta
from zoneinfo import ZoneInfo

from bot.bot import MoodBot
from bot.database import Database
from bot.dynamo import DynamoClient
from bot.init import initialize
from bot.model import Poll

_logger = logging.getLogger(__package__)

Expand All @@ -31,60 +25,6 @@ async def _close_polls(bot: MoodBot) -> None:
await bot.close()


async def _import_users(dynamo: DynamoClient, database: Database) -> None:
await database.open()
try:
async for user in dynamo.list_users():
_logger.info("Upserting user %s", user)
await database.upsert_user(user)
finally:
await database.close()


async def _import_user_groups(dynamo: DynamoClient, database: Database) -> None:
await database.open()
try:
async for user_id, group_id in dynamo.list_user_groups():
_logger.info("Linking user %d to group %d", user_id, group_id)
await database.add_to_group(user_id=user_id, group_id=group_id)
finally:
await database.close()


def _build_poll(*, poll_id: str, group_id: int, answer_time: datetime) -> Poll:
if answer_time.hour != 0:
raise ValueError(f"Unexcected answer time: {answer_time}")

tz = ZoneInfo("Europe/Berlin")
date = answer_time.date()
creation_time = datetime.combine(date, time(13), tzinfo=tz)
close_time = datetime.combine(date + timedelta(days=1), time(1), tzinfo=UTC)
return Poll(
id=poll_id,
group_id=group_id,
message_id=0,
creation_time=creation_time,
close_time=close_time,
)


async def _import_results(dynamo: DynamoClient, database: Database) -> None:
await database.open()
tz = ZoneInfo("Europe/Berlin")
try:
async for imported in dynamo.list_answers():
answer = imported.answer
plausible_time = datetime.combine(
answer.time.date(),
time(14),
tzinfo=tz,
)
answer = replace(answer, time=plausible_time)
await database.upsert_answer(answer)
finally:
await database.close()


def main() -> None:
config, database = initialize()

Expand All @@ -105,15 +45,6 @@ def main() -> None:
case "close-polls":
_logger.info("Closing polls")
asyncio.run(_close_polls(bot))
case "import-users":
_logger.info("Importing users")
asyncio.run(_import_users(DynamoClient(config.aws), database))
case "import-user-groups":
_logger.info("Importing user groups")
asyncio.run(_import_user_groups(DynamoClient(config.aws), database))
case "import-results":
_logger.info("Importing results")
asyncio.run(_import_results(DynamoClient(config.aws), database))
case other:
_logger.error("Unknown operation mode: %s", other)
sys.exit(1)
Expand Down
15 changes: 0 additions & 15 deletions src/bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,9 @@ def from_env(cls, env: Env) -> Self:
)


@dataclass(frozen=True, kw_only=True)
class AwsConfig:
access_key: str
secret_key: str

@classmethod
def from_env(cls, env: Env) -> Self:
return cls(
access_key=env.get_string("ACCESS_KEY", required=True),
secret_key=env.get_string("SECRET_KEY", required=True),
)


@dataclass(frozen=True, kw_only=True)
class Config:
active_chats: list[int]
aws: AwsConfig
database: DatabaseConfig
sentry: SentryConfig | None
telegram: TelegramConfig
Expand All @@ -82,7 +68,6 @@ class Config:
def from_env(cls, env: Env) -> Self:
return cls(
active_chats=env.get_int_list("ACTIVE_CHATS", required=True),
aws=AwsConfig.from_env(env.scoped("AWS_")),
database=DatabaseConfig.from_env(env.scoped("DATABASE_")),
sentry=SentryConfig.from_env(env),
telegram=TelegramConfig.from_env(env),
Expand Down
81 changes: 0 additions & 81 deletions src/bot/dynamo.py

This file was deleted.

0 comments on commit ed7ac89

Please sign in to comment.