-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
118 lines (98 loc) · 4.15 KB
/
Copy pathconfig.py
File metadata and controls
118 lines (98 loc) · 4.15 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
118
from pathlib import Path
import logging
import logging.config
logging.getLogger("httpx").disabled = True
logging.getLogger("httpcore").disabled = True
SETTINGS: dict[str, str] = {
"MAIN_CURRENCY": "USD",
"FILTER": {
"salary_from": [100, None],
"salary_to": [1000,2000],
"experience": "Нет опыта",
},
"API_PARAMS": {
'area': 113,
'per_page': 100,
'industry': 7,
'page': 0
}
}
""" all another params for search vacancy you can find on:
1. https://api.hh.ru/openapi/redoc#tag/Poisk-vakansij
2. https://api.hh.ru/dictionaries, but there not always correct info
all params for filter you can find in structure of database in database or in comments of script db/sql_handler. In order to use the filter without problems, I recommend reading the comments in core/filter.py """
class Project:
def __init__(self) -> None:
self.base_dir: Path = Path(__file__).parent
self._init_paths()
self._create_directories()
def _init_paths(self) -> None:
""" initialization directories and files paths """
self.tests_dir: Path = self.base_dir / "tests"
self.testdata: Path = self.tests_dir / "testdata.json"
self.data_dir: Path = self.base_dir / "data"
self.logs_dir: Path = self.data_dir / "logs"
self.charts_dir: Path = self.data_dir / "charts"
self.tmp_dir: Path = self.data_dir / "tmp"
self.db_file: Path = self.data_dir / "database.db"
self.vacancies_json: Path = self.data_dir / "vacancies.json"
self.tmpdb_file: Path = self.tmp_dir / "tmpdb.db"
self.overview_cvs: Path = self.tmp_dir / "overview.csv"
self.details_cvs: Path = self.tmp_dir / "details.csv"
def _create_directories(self) -> None:
""" Creating directories """
directories: list[Path] = [self.data_dir, self.logs_dir, self.charts_dir, self.tmp_dir]
for directory in directories:
directory.mkdir(parents=True, exist_ok=True)
def get_str_paths(self) -> dict[str, str]:
return {
'base': str(self.base_dir),
'tests': str(self.tests_dir),
'data': str(self.data_dir),
'logs': str(self.logs_dir),
'charts': str(self.charts_dir),
'database': str(self.db_file),
'vacancies': str(self.vacancies_json),
'testdata': str(self.testdata),
'tmp': str(self.tmp_dir),
'overview': str(self.overview_cvs),
'details': str(self.details_cvs),
'tmpdb': str(self.tmpdb_file)
}
def setup_logger(file_path: str,
log_name: str = "",
file_name: str = "app",
file_log_level: int = logging.DEBUG,
console_log_level: int = logging.INFO,
maxBytes: float = 1024*1024*5,
backupCount: int = 3) -> logging.Logger:
""" setup logger and getting it """
for lib in ['httpx', 'httpcore', 'h11', 'matplotlib', 'PIL']:
logging.getLogger(lib).setLevel(logging.WARNING)
try:
log_name = log_name if log_name else file_name
logger = logging.getLogger(log_name)
logger.setLevel(logging.DEBUG)
if logger.handlers:
logger.handlers.clear()
log_filename = f"{file_path}/{file_name}.log"
file_handler = logging.handlers.RotatingFileHandler(
log_filename,
maxBytes=maxBytes,
backupCount=backupCount
)
file_handler.setLevel(file_log_level)
file_handler.setFormatter(logging.Formatter(
'[%(asctime)s - %(name)s - %(levelname)s]: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
))
console_handler = logging.StreamHandler()
console_handler.setLevel(console_log_level)
console_handler.setFormatter(logging.Formatter(
'[%(levelname)s]: %(message)s'
))
logger.addHandler(file_handler)
logger.addHandler(console_handler)
return logger
except Exception as e:
raise Exception(f"error in setting logs: {e}")