Skip to content

Commit

Permalink
Merge pull request #312 from sysblok/dev
Browse files Browse the repository at this point in the history
Dev to master
  • Loading branch information
alexeyqu authored Mar 29, 2024
2 parents be7889a + 1bb2f5f commit 887f387
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<SYSBLOK_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`
Expand Down
4 changes: 4 additions & 0 deletions get_keys.sh
Original file line number Diff line number Diff line change
@@ -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 .
22 changes: 6 additions & 16 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""):
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 9 additions & 7 deletions src/facebook/facebook_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"]

Expand Down

0 comments on commit 887f387

Please sign in to comment.