Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #307

Merged
merged 24 commits into from
Mar 9, 2024
Merged

Test #307

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
72e8cd6
Added a more detailed error in case the user has a wrong json structure
gisly Mar 12, 2023
2d7dd1b
Merge pull request #293 from sysblok/feature/add-json-troubles-error
gisly Apr 6, 2023
0798f2a
hr pt acquisition job (#295)
alexeyqu Sep 10, 2023
af51fda
type comparisons have failed for some reason
alexeyqu Sep 10, 2023
beb9ec9
upd PyYAML to 6.0.1 per https://stackoverflow.com/a/76710304
alexeyqu Sep 10, 2023
2c0aa7c
fix
alexeyqu Sep 10, 2023
079e1fa
Merge branch 'master' into dev
alexeyqu Sep 10, 2023
c8bb18f
Checking if the web site is accessible at all
Oct 1, 2023
ec1537d
Merge pull request #297 from sysblok/feature/add-connection-error
gisly Oct 1, 2023
6871a09
Added an empty paragraph
Oct 1, 2023
18588cf
Merge pull request #298 from sysblok/feature/add-connection-error
gisly Oct 1, 2023
b3f2c27
Removed whitespace
Oct 1, 2023
1820ab5
Merge pull request #299 from sysblok/feature/add-connection-error
gisly Oct 1, 2023
0ab895e
Update site_health_check_job.py
gisly Nov 10, 2023
216f8d3
Added automatic string fetching when reloading the job config
Nov 11, 2023
5330c80
fix: rm legacy workflow
alexeyqu Dec 4, 2023
27900e0
feat: set up adding manager by @ (#303)
riveriswild Dec 29, 2023
d9de9c8
feat: add get_managers handler (#302)
riveriswild Dec 29, 2023
f648ceb
feat: add fetching all team members (#304)
ovrsun Dec 31, 2023
3c4ae47
fix:simplify get_tasks_report command & move extra features (#305)
riveriswild Jan 10, 2024
eb8b903
style: remove trailing whitespaces in user_message_handler
riveriswild Jan 10, 2024
cd200d7
fix: disable integration tests (#306)
ovrsun Jan 21, 2024
e1dda30
Merge pull request #301 from sysblok/feature/make-fetch-strings-with-…
gisly Jan 22, 2024
bd84668
feat: add MVP for calling Facebook API via requests
alexeyqu Jan 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions .github/workflows/publish_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,22 @@ jobs:
}' \
https://api.telegram.org/bot${{env.TELEGRAM_TEST_TOKEN}}/sendMessage

integration_tests:
needs: push

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
ref: dev

- name: Integration tests
uses: fylein/python-pytest-github-action@v2
env:
CONFIG_OVERRIDE: ${{ secrets.CONFIG_OVERRIDE_TESTING }}
with:
args: |
apt-get update && apt-get install -y git && \
pip3 install -e . && pip3 install -r requirements.txt && \
pytest tests/integration -vs
# integration_tests:
# needs: push

# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v2
# with:
# ref: dev

# - name: Integration tests
# uses: fylein/python-pytest-github-action@v2
# env:
# CONFIG_OVERRIDE: ${{ secrets.CONFIG_OVERRIDE_TESTING }}
# with:
# args: |
# apt-get update && apt-get install -y git && \
# pip3 install -e . && pip3 install -r requirements.txt && \
# pytest tests/integration -vs
38 changes: 19 additions & 19 deletions .github/workflows/publish_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,22 @@ jobs:
-d '{"parse_mode": "markdown", "chat_id": ${{ env.TELEGRAM_ERROR_CHAT_ID }}, "text": "[github CI] deploy [failed](https://github.com/sysblok/sysblokbot/actions/runs/${{github.run_id}})"}' \
https://api.telegram.org/bot${{env.TELEGRAM_TOKEN}}/sendMessage

integration_tests:
needs: push

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
ref: master

- name: Integration tests
uses: fylein/python-pytest-github-action@v2
env:
CONFIG_OVERRIDE: ${{ secrets.CONFIG_OVERRIDE_PROD }}
with:
args: |
apt-get update && apt-get install -y git && \
pip3 install -e . && pip3 install -r requirements.txt && \
pytest tests/integration -vs
# integration_tests:
# needs: push

# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v2
# with:
# ref: master

# - name: Integration tests
# uses: fylein/python-pytest-github-action@v2
# env:
# CONFIG_OVERRIDE: ${{ secrets.CONFIG_OVERRIDE_PROD }}
# with:
# args: |
# apt-get update && apt-get install -y git && \
# pip3 install -e . && pip3 install -r requirements.txt && \
# pytest tests/integration -vs
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
18 changes: 18 additions & 0 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ def init_handlers(self):
direct_message_only(handlers.get_tasks_report),
"получить список задач из Trello",
)
self.add_manager_handler(
"get_tasks_report_advanced",
CommandCategories.SUMMARY,
direct_message_only(handlers.get_tasks_report_advanced),
"получить список задач из Trello (расширенный)",
)
self.add_manager_handler(
"get_articles_arts",
CommandCategories.SUMMARY,
Expand Down Expand Up @@ -389,6 +395,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 +433,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
16 changes: 13 additions & 3 deletions src/facebook/facebook_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

import dateutil.parser as dateparser
import facebook
import requests

from ..consts import ReportPeriod
from ..utils.singleton import Singleton
from .facebook_objects import FacebookPage

logger = logging.getLogger(__name__)
BASE_URL = 'https://graph.facebook.com'
API_VERSION = 'v10.0'


class FacebookClient(Singleton):
Expand All @@ -32,13 +35,20 @@ def _update_from_config(self):
self._api_client = facebook.GraphAPI(self._facebook_config["token"], 7.0)
self._page_id = self._facebook_config["page_id"]

def _make_graph_api_call(self, uri: str, params: dict) -> dict:
params['access_token'] = self._facebook_config["token"]
response = requests.get(
'/'.join([BASE_URL, API_VERSION, uri]) + '?' +
'&'.join(f"{key}={value}" for key, value in params.items()))
return response.json()

def get_page(self) -> FacebookPage:
"""
Get facebook page
"""
page_dict = self._api_client.get_object(
self._page_id, fields="link,name,followers_count,fan_count"
)
page_dict = self._make_graph_api_call(str(self._page_id), {
'fields': 'link,name,followers_count,fan_count'
})
return FacebookPage.from_dict(page_dict)

def get_new_posts_count(self, since: datetime, until: datetime) -> int:
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
Loading
Loading