Compare commits

...

5 Commits

6 changed files with 415 additions and 385 deletions

View File

@ -23,13 +23,13 @@ jobs:
id: setup-python id: setup-python
uses: actions/setup-python@v3 uses: actions/setup-python@v3
with: with:
python-version: '3.10' python-version: '3.10.6'
#---------------------------------------------- #----------------------------------------------
# ----- install & configure poetry ----- # ----- install & configure poetry -----
#---------------------------------------------- #----------------------------------------------
- name: Install poetry - name: Install poetry
env: # Keep in sync with `POETRY_VERSION` in `Dockerfile` env: # Keep in sync with `POETRY_VERSION` in `Dockerfile`
POETRY_VERSION: "1.1.14" POETRY_VERSION: "1.2.0"
run: | run: |
curl -sSL "https://install.python-poetry.org" | python - curl -sSL "https://install.python-poetry.org" | python -
# Adding `poetry` to `$PATH`: # Adding `poetry` to `$PATH`:

View File

@ -23,13 +23,13 @@ jobs:
id: setup-python id: setup-python
uses: actions/setup-python@v3 uses: actions/setup-python@v3
with: with:
python-version: '3.10' python-version: '3.10.6'
#---------------------------------------------- #----------------------------------------------
# ----- install & configure poetry ----- # ----- install & configure poetry -----
#---------------------------------------------- #----------------------------------------------
- name: Install poetry - name: Install poetry
env: # Keep in sync with `POETRY_VERSION` in `Dockerfile` env: # Keep in sync with `POETRY_VERSION` in `Dockerfile`
POETRY_VERSION: "1.1.14" POETRY_VERSION: "1.2.0"
run: | run: |
curl -sSL "https://install.python-poetry.org" | python - curl -sSL "https://install.python-poetry.org" | python -
# Adding `poetry` to `$PATH`: # Adding `poetry` to `$PATH`:

View File

@ -90,7 +90,9 @@ class TransportBot:
) )
@staticmethod @staticmethod
async def morning_bus_mailing(chat_ids: list[int] | None) -> None: async def morning_bus_mailing(
chat_ids: list[int] | None, show_keyboard: bool = False
) -> None:
if not chat_ids: if not chat_ids:
return None return None
@ -104,10 +106,15 @@ class TransportBot:
'т19', 'т19',
], ],
) )
kwargs = {'reply_markup': TransportBot.get_keyboard()} if show_keyboard else {}
await asyncio.gather( await asyncio.gather(
*[ *[
TransportBot.bot.send_message( TransportBot.bot.send_message(
chat_id=chat_id, text=text, parse_mode=types.ParseMode.HTML chat_id=chat_id,
text=text,
parse_mode=types.ParseMode.HTML,
**kwargs
) )
for chat_id in chat_ids for chat_id in chat_ids
] ]

View File

@ -9,25 +9,32 @@ bot_cron_jobs = {
'job': TransportBot.morning_bus_mailing, 'job': TransportBot.morning_bus_mailing,
'cron': [ 'cron': [
{ {
'trigger': 'cron', 'time': {
'day_of_week': 'mon-fri', 'trigger': 'cron',
'hour': 8, 'day_of_week': 'mon-fri',
'minute': 59, 'hour': 8,
'second': 0, 'minute': 59,
'second': 0,
},
}, },
{ {
'trigger': 'cron', 'time': {
'day_of_week': 'mon-fri', 'trigger': 'cron',
'hour': 9, 'day_of_week': 'mon-fri',
'minute': 4, 'hour': 9,
'second': 0, 'minute': 4,
'second': 0,
},
}, },
{ {
'trigger': 'cron', 'time': {
'day_of_week': 'mon-fri', 'trigger': 'cron',
'hour': 9, 'day_of_week': 'mon-fri',
'minute': 9, 'hour': 9,
'second': 0, 'minute': 9,
'second': 0,
},
'kwargs_per_job': {'show_keyboard': True},
}, },
], ],
'func_kwargs': { 'func_kwargs': {
@ -54,7 +61,11 @@ class BotScheduler:
return None return None
for cron in cron_jobs['cron']: for cron in cron_jobs['cron']:
self.scheduler.add_job( self.scheduler.add_job(
cron_jobs['job'], kwargs=cron_jobs.get('func_kwargs'), **cron cron_jobs['job'],
kwargs=dict(
**cron_jobs.get('func_kwargs'), **cron.get('kwargs_per_job', {})
),
**cron['time'],
) )
logger.info(f'Added scheduled job: {cron_jobs["job"].__name__} {cron}') logger.info(f'Added scheduled job: {cron_jobs["job"].__name__} {cron}')

View File

@ -30,7 +30,7 @@ RUN printf "================\n\nStart build app. USER is: "${USER}"\n\n=========
sshpass \ sshpass \
&& pip install --upgrade pip \ && pip install --upgrade pip \
# Installing `poetry` package manager: # Installing `poetry` package manager:
&& pip install poetry \ && pip install poetry wheel\
# Cleaning cache: # Cleaning cache:
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* && apt-get clean -y && rm -rf /var/lib/apt/lists/*
@ -47,7 +47,7 @@ RUN if [ "$USER" != "root" ]; then \
COPY --chown="$USER":"$USER" ./poetry.lock ./pyproject.toml /app/ COPY --chown="$USER":"$USER" ./poetry.lock ./pyproject.toml /app/
# Installing requirements # Installing requirements
RUN poetry version \ RUN poetry --version \
&& poetry run pip install -U pip \ && poetry run pip install -U pip \
&& poetry install \ && poetry install \
$(if [ "$USER" != 'root' ]; then echo '--no-dev'; fi) \ $(if [ "$USER" != 'root' ]; then echo '--no-dev'; fi) \

734
poetry.lock generated

File diff suppressed because it is too large Load Diff