-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
40 lines (28 loc) · 1.31 KB
/
functions.py
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
import requests
def format_candidates(candidates: list[dict[str, int | str]]) -> str:
'''Упрощённый вид'''
result: str = '<pre>'
for candidate in candidates:
result += f'{candidate["name"]}\n' \
f'{candidate["position"]}\n' \
f'{candidate["skills"]}\n' \
f'<pre>'
return result
def get_all() -> list[dict[str, int | str]]:
'''Возвращает всех кандидатов'''
return requests.get('https://www.jsonkeeper.com/b/G9LL').json()
def get_by_pk(pk_name: int) -> dict[str, int | str] | str:
'''Возвращает кандидата по pk, если такого кандитата не было найдено, выведет неправильный pk'''
candidates: list[dict[str, int | str]] = get_all()
for candidate in candidates:
if candidate["pk"] == pk_name:
return candidate
return 'Wrong pk'
def get_by_skill(skill_name: str) -> list[dict[str, int | str]]:
'''Возвращает список кандидатов по навыкам'''
candidates: list[dict[str, int | str]] = get_all()
result: list = []
for candidate in candidates:
if skill_name in candidate["skills"].lower().split(', '):
result.append(candidate)
return result