Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
"sheets": {
"api_key_path": "do_not_set_here_please_go_to_config_override",
"authors_sheet_key": "do_not_set_here_please_go_to_config_override",
"curators_sheet_key": "do_not_set_here_please_go_to_config_override",
"hr_sheet_key": "do_not_set_here_please_go_to_config_override",
"hr_pt_sheet_key": "do_not_set_here_please_go_to_config_override",
Expand Down
8 changes: 0 additions & 8 deletions src/app_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
from .db.db_client import DBClient
from .drive.drive_client import GoogleDriveClient
from .facebook.facebook_client import FacebookClient
from .focalboard.focalboard_client import FocalboardClient
from .instagram.instagram_client import InstagramClient
from .n8n.n8n_client import N8nClient
from .planka.planka_client import PlankaClient
from .sheets.sheets_client import GoogleSheetsClient
from .strings import StringsDBClient
from .tg.tg_client import TgClient
from .trello.trello_client import TrelloClient
from .utils.singleton import Singleton

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -47,12 +45,6 @@ def __init__(
self.strings_db_client.fetch_strings_sheet(self.sheets_client)
self.db_client.fetch_all(self.sheets_client)

self.trello_client = TrelloClient(
trello_config=config_manager.get_trello_config()
)
self.focalboard_client = FocalboardClient(
focalboard_config=config_manager.get_focalboard_config()
)
self.planka_client = PlankaClient(
planka_config=config_manager.get_planka_config()
)
Expand Down
6 changes: 0 additions & 6 deletions src/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ def get_latest_jobs_config(self):
logger.debug(f"Got config, last updated: {self._latest_jobs_config_ts}")
return self._latest_jobs_config

def get_trello_config(self):
return self.get_latest_config().get(consts.TRELLO_CONFIG, {})

def get_focalboard_config(self):
return self.get_latest_config().get(consts.FOCALBOARD_CONFIG, {})

def get_planka_config(self):
return self.get_latest_config().get(consts.PLANKA_CONFIG, {})

Expand Down
6 changes: 0 additions & 6 deletions src/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class AppSource(Enum):

# Upper level config keys
TELEGRAM_CONFIG = "telegram"
TRELLO_CONFIG = "trello"
FOCALBOARD_CONFIG = "focalboard"
PLANKA_CONFIG = "planka"
SHEETS_CONFIG = "sheets"
DRIVE_CONFIG = "drive"
Expand All @@ -59,9 +57,6 @@ class AppSource(Enum):
# Telegram keys
TELEGRAM_MANAGER_IDS = "manager_chat_ids"

# Trello keys
TRELLO_BOARD_ID = "board_id"

# Vk consts
VK_POST_LINK = "https://vk.com/{group_alias}?w=wall-{group_id}_{post_id}"

Expand Down Expand Up @@ -166,7 +161,6 @@ class PlainTextUserAction(Enum):
"""

# /get_tasks_report items
GET_TASKS_REPORT__ENTER_BOARD_URL = "get_tasks_report__board_url"
GET_TASKS_REPORT__ENTER_BOARD_NUMBER = "get_tasks_report__board_number"
GET_TASKS_REPORT__ENTER_LIST_NUMBER = "get_tasks_report__list_number"
GET_TASKS_REPORT__ENTER_INTRO = "get_tasks_report__introduction"
Expand Down
42 changes: 14 additions & 28 deletions src/db/db_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from .. import consts
from ..sheets.sheets_client import GoogleSheetsClient
from ..utils.singleton import Singleton
from ..utils.telegram import normalize_telegram_username
from .db_objects import (
Author,
Base,
Chat,
Curator,
Expand Down Expand Up @@ -67,28 +67,10 @@ def _ensure_team_telegram_id_column(self):
)

def fetch_all(self, sheets_client: GoogleSheetsClient):
self.fetch_authors_sheet(sheets_client)
self.fetch_curators_sheet(sheets_client)
self.fetch_team_sheet(sheets_client)
self.fetch_rubrics_sheet(sheets_client)

def fetch_authors_sheet(self, sheets_client: GoogleSheetsClient):
session = self.Session()
try:
# clean this table
session.query(Author).delete()
# re-download it
authors = sheets_client.fetch_authors()
for item in authors:
author = Author.from_sheetfu_item(item)
session.add(author)
session.commit()
except Exception as e:
logger.warning("Failed to update authors table from sheet", exc_info=e)
session.rollback()
return 0
return len(authors)

def fetch_curators_sheet(self, sheets_client: GoogleSheetsClient):
session = self.Session()
try:
Expand Down Expand Up @@ -201,17 +183,21 @@ def find_focalboard_username_by_telegram_username(self, telegram_username: str):
return member.focalboard

def find_author_telegram_by_trello(self, trello_id: str):
# TODO: make batch queries
session = self.Session()
author = (
session.query(Author)
.filter((Author.trello == trello_id) | (Author.focalboard == trello_id))
.first()
normalized = normalize_telegram_username(trello_id)
members = self.Session().query(TeamMember).all()
member = next(
(
m
for m in members
if normalize_telegram_username(m.trello) == normalized
or normalize_telegram_username(m.focalboard) == normalized
),
None,
)
if author is None:
logger.warning(f"Telegram id not found for author {trello_id}")
if member is None:
logger.warning(f"Telegram id not found for team member {trello_id}")
return None
return author.telegram
return member.telegram

def get_curator_by_telegram(self, telegram: str) -> Curator:
session = self.Session()
Expand Down
50 changes: 1 addition & 49 deletions src/db/db_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,58 +43,10 @@ def process_result_value(self, value, dialect):
return value


class Author(Base):
__tablename__ = "authors"

name = Column(String, primary_key=True)
curator = Column(String)
status = Column(String)
telegram = Column(String)
trello = Column(String)
focalboard = Column(String)

def __repr__(self):
return f"Author {self.name} tg={self.telegram} trello={self.trello} f={self.focalboard}"

@classmethod
def from_dict(cls, data):
author = cls()
author.name = _get_str_data_item(data, "name")
author.curator = _get_str_data_item(data, "curator")
author.status = _get_str_data_item(data, "status")
author.telegram = _get_str_data_item(data, "telegram")
author.trello = _get_str_data_item(data, "trello")
author.focalboard = _get_str_data_item(data, "focalboard")
return author

def to_dict(self):
return {
"name": self.name,
"curator": self.curator,
"status": self.status,
"telegram": self.telegram,
"trello": self.trello,
"focalboard": self.focalboard,
}

@classmethod
def from_sheetfu_item(cls, item):
author = cls()
author.name = item.get_field_value(load("sheets__what_is_your_name"))
author.curator = item.get_field_value(load("sheets__curator_as_author"))
author.status = item.get_field_value(load("sheets__status"))
author.telegram = item.get_field_value(load("sheets__telegram"))
author.trello = item.get_field_value(load("sheets__trello"))
author.focalboard = item.get_field_value(load("sheets__focalboard"))
return author


class Curator(Base):
__tablename__ = "curators"

role = Column(
String, ForeignKey("authors.curator"), primary_key=True
) # e.g. "Куратор NLP 1"
role = Column(String, primary_key=True) # e.g. "Куратор NLP 1"
name = Column(String, primary_key=True)
telegram = Column(String)
team = Column(String) # e.g. "Авторы"
Expand Down
2 changes: 1 addition & 1 deletion src/drive/drive_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from googleapiclient.http import MediaIoBaseDownload
from oauth2client.service_account import ServiceAccountCredentials

from ..trello.trello_objects import TrelloCard
from ..planka.board_objects import TrelloCard
from ..utils.singleton import Singleton

logger = logging.getLogger(__name__)
Expand Down
Loading
Loading