-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_processing.py
More file actions
117 lines (105 loc) · 3.99 KB
/
db_processing.py
File metadata and controls
117 lines (105 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import re
from sqlite3 import Cursor, Connection
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
from datetime import datetime
class Vacancy:
def __init__(self, vacancy_info: list) -> None:
self.id = vacancy_info[0]
self.title = vacancy_info[1]
self.employer = vacancy_info[2]
self.employer_url = vacancy_info[3]
self.salary = vacancy_info[4]
self.address = vacancy_info[5]
self.requirements = vacancy_info[6]
self.responsibilities = vacancy_info[7]
self.vacancy_url = vacancy_info[8]
self.response_url = vacancy_info[9]
self.created_at = self.convert_input_datetime(vacancy_info[10])
self.responded = vacancy_info[11]
self.processed = vacancy_info[12]
def convert_input_datetime(self, hh_datetime) -> datetime:
year, month, day, hour, minute, second, _ = [int(x) for x in re.split(r'[-T:+]', hh_datetime)]
return datetime(year, month, day, hour, minute, second, 0)
def message(self):
message = self.title
if self.salary:
message += f'\n{self.salary}'
if self.employer:
message += f'\nРаботодатель: {self.employer}'
if self.address:
message += f'\n{self.address}'
if self.requirements:
message += f'\n\nОжидания:\n{self.requirements}'
if self.responsibilities:
message += f'\n\nЧем предстоит заниматься:\n{self.responsibilities}'
message += f'\n\n{self.created_at.strftime("%d.%m.%Y %H:%M")}'
return message
def make_tg_inline_keyboard(self):
buttons = list()
if self.vacancy_url:
buttons.append([
InlineKeyboardButton(
text='подробнее о вакансии',
url=self.vacancy_url
)
])
if self.vacancy_url:
buttons.append([
InlineKeyboardButton(
text='подробнее о работодателе',
url=self.employer_url
)
])
if self.vacancy_url:
buttons.append([
InlineKeyboardButton(
text='откликнуться',
url=self.response_url
)
])
buttons.append([
InlineKeyboardButton(
text='отклик отправлен',
callback_data=f'response_vacancy:{self.id}'
)
])
if self.vacancy_url:
buttons.append([
InlineKeyboardButton(
text='в архив',
callback_data=f'archive_vacancy:{self.id}'
)
])
return InlineKeyboardMarkup(buttons)
def add_vacancy(db: Connection, cursor: Cursor, vacancy_info: list):
assert len(vacancy_info) == 13
cursor.execute(
"INSERT INTO vacancies VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
vacancy_info
)
db.commit()
def get_active_vacancy(db: Connection, cursor: Cursor) -> Vacancy:
vacancy_info = cursor.execute(
"SELECT * FROM vacancies WHERE processed = False LIMIT 1"
).fetchone()
return Vacancy(vacancy_info)
def count_active_vacancies(db: Connection, cursor: Cursor):
return cursor.execute(
"SELECT COUNT(*) FROM vacancies WHERE processed = False"
).fetchone()[0]
def update_response_and_process_statuses(db: Connection,
cursor: Cursor,
vacancy_id: int) -> None:
cursor.execute(
"""UPDATE vacancies SET responded = 1, processed = 1 WHERE id = ?""",
(vacancy_id,)
)
db.commit()
def update_process_status(db: Connection,
cursor: Cursor,
vacancy_id: int) -> None:
cursor.execute(
"""UPDATE vacancies SET processed = 1 WHERE id = ?""",
(vacancy_id,)
)
db.commit()