diff --git a/README.md b/README.md index e8ba119..9f9dd74 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,14 @@ Bot for SysBlok ("Системный Блокъ") editorial processes automatization. ## How to make a first local run +- You might need to set up `ru_RU.UTF-8` locale. To do that, run + - `sudo locale-gen "ru_RU.UTF-8"` + - `sudo dpkg-reconfigure locales` - Create a testing bot through BotFather and obtain the token. - Create `config_override.json` in the same directory and put sensitive tokens there (you can copypaste from `config.json` first). Do not push `config_override.json` to the repo! + - Run `export INFRA_HOST=`, putting in the actual URL + - Run `sh get_keys.sh`. This will download `config_override.json` and `config_gs.json` to your folder. +- Replace `YOUR_CHAT_ID`, `YOUR_USERNAME` and `BOT_TOKEN` with appropriate values - `pip install -e .` - `pip install -r requirements.txt` - `pre-commit install` diff --git a/get_keys.sh b/get_keys.sh new file mode 100644 index 0000000..897fefa --- /dev/null +++ b/get_keys.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +scp sysblokbot-dev@$INFRA_HOST:/home/sysblokbot-dev/config_gs.json . +scp sysblokbot-dev@$INFRA_HOST:/home/sysblokbot-dev/config_override.json . diff --git a/src/bot.py b/src/bot.py index 6cf724f..e531465 100644 --- a/src/bot.py +++ b/src/bot.py @@ -408,36 +408,26 @@ def init_handlers(self): self.admin_reply_handler("sample_job"), ) - # admin-only DB cmds - self.add_admin_handler( + # db commands hidden from /help command + self.add_handler( "db_fetch_authors_sheet", - CommandCategories.DATA_SYNC, self.admin_reply_handler("db_fetch_authors_sheet_job"), - "обновить таблицу с авторами из Google Sheets", ) - self.add_admin_handler( + self.add_handler( "db_fetch_curators_sheet", - CommandCategories.DATA_SYNC, self.admin_reply_handler("db_fetch_curators_sheet_job"), - "обновить таблицу с кураторами из Google Sheets", ) - self.add_admin_handler( + self.add_handler( "db_fetch_team_sheet", - CommandCategories.DATA_SYNC, self.admin_reply_handler("db_fetch_team_sheet_job"), - "обновить таблицу с командой из Google Sheets", ) - self.add_admin_handler( + self.add_handler( "db_fetch_strings_sheet", - CommandCategories.DATA_SYNC, self.admin_reply_handler("db_fetch_strings_sheet_job"), - "обновить таблицу со строками из Google Sheets", ) - self.add_admin_handler( + self.add_handler( "db_fetch_all_team_members", - CommandCategories.DATA_SYNC, self.admin_reply_handler("db_fetch_all_team_members_job"), - "обновить таблицы всех пользователей (авторов, кураторов, команда) из Google Sheets", ) # general purpose cmds diff --git a/src/config_manager.py b/src/config_manager.py index b114c34..02a8607 100644 --- a/src/config_manager.py +++ b/src/config_manager.py @@ -7,8 +7,6 @@ logger = logging.getLogger(__name__) -REDACTED_KEYS = ("key", "token") - class ConfigManager(Singleton): def __init__(self, config_path: str = "", config_override_path: str = ""): @@ -141,7 +139,7 @@ def redact(config: dict) -> dict: redacted_config[key] = ConfigManager.redact(value) else: redacted_config[key] = value - for redacted_key in REDACTED_KEYS: + for redacted_key in consts.REDACTED_KEYS: if redacted_key in key: redacted_config[key] = "XXXXX" break diff --git a/src/consts.py b/src/consts.py index c2cc2a9..c61c896 100644 --- a/src/consts.py +++ b/src/consts.py @@ -60,6 +60,9 @@ class AppSource(Enum): # Vk consts VK_POST_LINK = "https://vk.com/{group_alias}?w=wall-{group_id}_{post_id}" +# List of keys whose values need to be hidden +REDACTED_KEYS = ("key", "token", "id", "hash", "session") + # Report enum class ReportPeriod(Enum): diff --git a/src/facebook/facebook_client.py b/src/facebook/facebook_client.py index eaa2ecc..caa55b8 100644 --- a/src/facebook/facebook_client.py +++ b/src/facebook/facebook_client.py @@ -14,7 +14,7 @@ logger = logging.getLogger(__name__) BASE_URL = 'https://graph.facebook.com' -API_VERSION = 'v10.0' +API_VERSION = 'v19.0' class FacebookClient(Singleton): @@ -55,12 +55,14 @@ def get_new_posts_count(self, since: datetime, until: datetime) -> int: """ Get the number of new posts for the period. """ - result = self._api_client.get_connections( - self._page_id, - connection_name="published_posts", - summary="total_count", - since=since, - until=until, + result = self._make_graph_api_call( + str(self._page_id) + '/published_posts', + { + 'summary': 'total_count', + 'since': int(datetime.timestamp(since)), + 'until': int(datetime.timestamp(until)), + 'limit': 0, + } ) return result["summary"]["total_count"]