Skip to content

Commit

Permalink
Dev to master (#300)
Browse files Browse the repository at this point in the history
* Added a more detailed error in case the user has a wrong json structure

* hr pt acquisition job (#295)

* hr pt acquisition job

* works

* type comparisons have failed for some reason

* upd PyYAML to 6.0.1 per https://stackoverflow.com/a/76710304

* fix

* Checking if the web site is accessible at all

* Added an empty paragraph

* Removed whitespace

* Update site_health_check_job.py

* fix: rm legacy workflow

* feat: set up adding manager by @ (#303)

feat: set up adding manager by @

* feat: add get_managers handler (#302)

feat: add get_managers handler

* feat: add fetching all team members (#304)

---------

Co-authored-by: Alex Kulikov <7394728+alexeyqu@users.noreply.github.com>
Co-authored-by: Alexey Kulikov <alexeyqu@gmail.com>
Co-authored-by: gisly <gisly@mail.ru>
Co-authored-by: River <79055927+riveriswild@users.noreply.github.com>
Co-authored-by: ovrsun <115068324+ovrsun@users.noreply.github.com>
  • Loading branch information
6 people authored Jan 10, 2024
1 parent 90fb7fb commit 50a0437
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 144 deletions.
137 changes: 0 additions & 137 deletions .github/workflows/publish_master_lobanov.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ config_override.json
src/sheets/sysblokbot.json
persistent_storage.pickle
*.sqlite-journal
config_gs.json

*.sqlite

*.token

Expand Down
12 changes: 12 additions & 0 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ def init_handlers(self):
handlers.clean_chat_data,
"clean_chat_data",
)
self.add_admin_handler(
"get_managers",
CommandCategories.MOST_USED,
handlers.get_managers,
"get_managers",
)

# sample handler
self.add_handler(
Expand Down Expand Up @@ -421,6 +427,12 @@ def init_handlers(self):
self.admin_reply_handler("db_fetch_strings_sheet_job"),
"обновить таблицу со строками из Google Sheets",
)
self.add_admin_handler(
"db_fetch_all_team_members",
CommandCategories.DATA_SYNC,
self.admin_reply_handler("db_fetch_all_team_members_job"),
"обновить таблицы всех пользователей (авторов, кураторов, команда) из Google Sheets",
)

# general purpose cmds
self.add_admin_handler(
Expand Down
1 change: 1 addition & 0 deletions src/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .config_updater_job import ConfigUpdaterJob
from .create_folders_for_illustrators_job import CreateFoldersForIllustratorsJob
from .db_fetch_all_team_members_job import DBFetchAllTeamMembersJob
from .db_fetch_authors_sheet_job import DBFetchAuthorsSheetJob
from .db_fetch_curators_sheet_job import DBFetchCuratorsSheetJob
from .db_fetch_strings_sheet_job import DBFetchStringsSheetJob
Expand Down
34 changes: 34 additions & 0 deletions src/jobs/db_fetch_all_team_members_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import logging
from typing import Callable

from ..app_context import AppContext
from ..strings import load
from .base_job import BaseJob

logger = logging.getLogger(__name__)


class DBFetchAllTeamMembersJob(BaseJob):
@staticmethod
def _execute(
app_context: AppContext, send: Callable[[str], None], called_from_handler=False
):
num_authors = app_context.db_client.fetch_authors_sheet(
app_context.sheets_client
)
logger.info(f"Fetched {num_authors} authors")
send(load("db_fetch_authors_sheet_job__success", num_authors=num_authors))

num_curators = app_context.db_client.fetch_curators_sheet(
app_context.sheets_client
)
logger.info(f"Fetched {num_curators} curators")
send(load("db_fetch_curators_sheet_job__success", num_curators=num_curators))

team_size = app_context.db_client.fetch_team_sheet(
app_context.sheets_client
)
# after we fetch the team, we need to recalculate the roles
app_context.role_manager.calculate_db_roles()
logger.info(f"Fetched {team_size} team members")
send(load("db_fetch_team_sheet_job__success", team_size=team_size))
2 changes: 1 addition & 1 deletion src/jobs/hr_acquisition_pt_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _process_raw_forms(

for person in new_people:
# filter out incomplete responses
if not person.telegram and not person.other_contacts:
if not person.telegram:
person.status = load("sheets__hr__pt__raw__status_rejection")
continue
if person.telegram and (
Expand Down
15 changes: 13 additions & 2 deletions src/jobs/site_health_check_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ def _execute(
kwargs = schedule[KWARGS]
url = kwargs.get("index_url")
logger.debug(f"Checking site health for {kwargs.get('name')}: {url}")
page = requests.get(url)
try:
page = requests.get(url)
except Exception as e:
send(
load(
"site_health_check_job__connection_error",
url=url,
)
)
logger.error(f"Connection error for {url}")
return

if page.status_code != 200:
send(
load(
Expand All @@ -68,7 +79,7 @@ def _execute(
logger.error(f"Bad body contents for {url}")
logger.warning(f"Html:\n\n{body_contents}")
return
logger.debug("Site contents look healthy")
logger.debug("Site content looks healthy")
if called_from_handler:
send(
load(
Expand Down
1 change: 1 addition & 0 deletions src/tg/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .error_handler import error
from .get_chat_data_handler import get_chat_data
from .get_chat_id_handler import get_chat_id_handler as get_chat_id
from .get_managers_handler import get_managers
from .get_members_for_role_handler import get_members_for_role

# Admin (developer) handlers
Expand Down
10 changes: 6 additions & 4 deletions src/tg/handlers/access_config_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ def add_manager(update, tg_context):
try:
tokens = update.message.text.strip().split(maxsplit=2)
assert len(tokens) == 2
manager_id = json.loads(tokens[1])
assert isinstance(manager_id, int) or (
isinstance(manager_id, str) and not manager_id.startswith("@")
)
try:
manager_id = json.loads(tokens[1])
except Exception:
manager_id = tokens[1]
manager_id = manager_id.lstrip("@")
assert isinstance(manager_id, int) or isinstance(manager_id, str)
config_manager = ConfigManager()
manager_ids = config_manager.get_telegram_config()[consts.TELEGRAM_MANAGER_IDS][
:
Expand Down
10 changes: 10 additions & 0 deletions src/tg/handlers/get_managers_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ... import consts
from ...config_manager import ConfigManager
from .utils import admin_only, reply


@admin_only
def get_managers(update, tg_context):
config_manager = ConfigManager()
manager_ids = config_manager.get_telegram_config()[consts.TELEGRAM_MANAGER_IDS][:]
reply(str(manager_ids), update)

0 comments on commit 50a0437

Please sign in to comment.