Skip to content

Commit

Permalink
hr pt acquisition job (#295)
Browse files Browse the repository at this point in the history
* hr pt acquisition job

* works
  • Loading branch information
alexeyqu authored Sep 10, 2023
1 parent 2d7dd1b commit 0798f2a
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"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",
"post_registry_sheet_key": "do_not_set_here_please_go_to_config_override",
"postcards_sheet_key": "do_not_set_here_please_go_to_config_override",
"rubrics_registry_sheet_key": "do_not_set_here_please_go_to_config_override",
Expand Down
6 changes: 6 additions & 0 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ def init_handlers(self):
self.manager_reply_handler("hr_acquisition_job"),
"обработать новые анкеты",
)
self.add_admin_handler(
"hr_acquisition_pt",
CommandCategories.HR,
self.manager_reply_handler("hr_acquisition_pt_job"),
"обработать новые анкеты Пишу Тебе",
)
self.add_manager_handler(
"get_hr_status",
CommandCategories.HR,
Expand Down
1 change: 1 addition & 0 deletions src/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .fb_analytics_report_job import FBAnalyticsReportJob
from .fill_posts_list_job import FillPostsListJob
from .hr_acquisition_job import HRAcquisitionJob
from .hr_acquisition_pt_job import HRAcquisitionPTJob
from .hr_check_chat_consistency_frozen_job import HRCheckChatConsistencyFrozenJob
from .hr_check_chat_consistency_job import HRCheckChatConsistencyJob
from .hr_check_trello_consistency_frozen_job import HRCheckTrelloConsistencyFrozenJob
Expand Down
108 changes: 108 additions & 0 deletions src/jobs/hr_acquisition_pt_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import logging
from typing import Callable, List

from sheetfu import Table

from ..app_context import AppContext
from ..sheets.sheets_objects import HRPersonPTProcessed, HRPersonPTRaw
from ..strings import load
from ..tg.sender import pretty_send
from .base_job import BaseJob

logger = logging.getLogger(__name__)


class HRAcquisitionPTJob(BaseJob):
@staticmethod
def _execute(
app_context: AppContext, send: Callable[[str], None], called_from_handler=False
):
paragraphs = [load("hr_acquisition_job__hello")] # list of paragraph strings

new_people = HRAcquisitionPTJob._process_new_people(app_context)

if not new_people:
return

paragraphs += [
HRAcquisitionPTJob._get_new_person_paragraph(item) for item in new_people
]

pretty_send(paragraphs, send)

@staticmethod
def _process_new_people(
app_context: AppContext,
) -> List[HRPersonPTProcessed]:
forms_raw = app_context.sheets_client.fetch_hr_pt_forms_raw()
forms_processed = app_context.sheets_client.fetch_hr_pt_forms_processed()

new_items = HRAcquisitionPTJob._process_raw_forms(forms_raw, forms_processed)

try:
forms_raw.commit()
forms_processed.commit()
except Exception as e:
logger.error(f"failed to export data: {e}")

return new_items

@staticmethod
def _process_raw_forms(
forms_raw: Table, forms_processed: Table
) -> List[HRPersonPTProcessed]:
people = [HRPersonPTRaw(item) for item in forms_raw]
existing_people = [person for person in people if person.status]
new_people = [person for person in people if not person.status]
new_items = []

for person in new_people:
# filter out incomplete responses
if not person.telegram and not person.other_contacts:
person.status = load("sheets__hr__pt__raw__status_rejection")
continue
if person.telegram and (
person.telegram in {person.telegram for person in existing_people}
or person.telegram in {person.telegram for person in new_items}
):
person.status = load("sheets__hr__pt__raw__status_double")
continue

# move good ones to another sheet
person.status = load("sheets__hr__pt__raw__status_processed")
# TODO: PR to sheetfu which will allow better API here
person_dict = {
"id": len(forms_processed)
+ 2, # 1 for starting with 1 and 1 for the header
"name": person.name,
"interests": person.interests,
"about": person.about,
"date_submitted": person.ts,
"referral": person.referral,
"telegram": person.telegram,
"status": "TODO", # this is a legitimate value, not an actual TODO
}
new_items.append(
HRPersonPTProcessed.add_one_to_table(forms_processed, person_dict)
)

return new_items

@staticmethod
def _get_new_person_paragraph(item: HRPersonPTProcessed) -> str:
name = load(
"hr_acquisition_job__name",
name=item.name,
telegram=item.telegram,
date=item.date_submitted.split(" ")[0],
)
interests = load("hr_acquisition_job__interests", interests=item.interests)
about = load("hr_acquisition_job__about", description=item.about)
paragraph = load(
"hr_acquisition_job__person",
name=name,
interests=interests,
about=about,
contacts="", # no other contacts field in PT
)
return paragraph
7 changes: 7 additions & 0 deletions src/sheets/sheets_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def _update_from_config(self):
self.authors_sheet_key = self._sheets_config["authors_sheet_key"]
self.curators_sheet_key = self._sheets_config["curators_sheet_key"]
self.hr_sheet_key = self._sheets_config["hr_sheet_key"]
self.hr_pt_sheet_key = self._sheets_config["hr_pt_sheet_key"]
self.post_registry_sheet_key = self._sheets_config["post_registry_sheet_key"]
self.rubrics_registry_sheet_key = self._sheets_config[
"rubrics_registry_sheet_key"
Expand Down Expand Up @@ -57,6 +58,12 @@ def fetch_hr_forms_raw(self) -> Table:
def fetch_hr_forms_processed(self) -> Table:
return self._fetch_table(self.hr_sheet_key, "Анкеты")

def fetch_hr_pt_forms_raw(self) -> Table:
return self._fetch_table(self.hr_pt_sheet_key, "Ответы Главный сайт")

def fetch_hr_pt_forms_processed(self) -> Table:
return self._fetch_table(self.hr_pt_sheet_key, "Анкеты")

def fetch_hr_team(self) -> Table:
return self._fetch_table(self.hr_sheet_key, "Команда (с заморозкой)")

Expand Down
25 changes: 25 additions & 0 deletions src/sheets/sheets_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,31 @@ class HRPersonProcessed(SheetsItem):
}


class HRPersonPTRaw(SheetsItem):
field_alias = {
"ts": "sheets__hr__pt__raw__timestamp",
"name": "sheets__hr__pt__raw__name",
"interests": "sheets__hr__pt__raw__interests",
"about": "sheets__hr__pt__raw__about",
"telegram": "sheets__hr__pt__raw__telegram",
"referral": "sheets__hr__pt__raw__referral",
"status": "sheets__hr__raw__status",
}


class HRPersonPTProcessed(SheetsItem):
field_alias = {
"id": "sheets__hr__pt__processed__id",
"name": "sheets__hr__pt__processed__name",
"interests": "sheets__hr__pt__processed__interests",
"about": "sheets__hr__pt__processed__about",
"referral": "sheets__hr__pt__processed__referral",
"date_submitted": "sheets__hr__pt__processed__date_submitted",
"telegram": "sheets__hr__pt__processed__telegram",
"status": "sheets__hr__pt__processed__status",
}


class PostRegistryItem(SheetsItem):
field_alias = {
"name": "sheets__post_registry__column_name",
Expand Down

0 comments on commit 0798f2a

Please sign in to comment.