-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.py
131 lines (102 loc) · 8.94 KB
/
config.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
import re
import pathlib
# Flag to print logs
LOG = True
# Change this to set the destination of all the questions
# PARENT_DIR must be an instance of pathlib.Path
PARENT_DIR:pathlib.Path = pathlib.Path(r"./All Questions/")
PARENT_DIR.mkdir(parents=True, exist_ok=True)
# Get auth_key by inspecting network calls
# 1. Open Chrome Devtools
# 2. Network Tab
# 3. Inspect a request that requires auth_key(Ex: https://prod.api.algoexpert.io/api/problems/v1/run_json_tests)
# 4. find `authorization` header in the request headers section
AUTH_KEY = "YOUR AUTH_KEY"
# ================================================================
# Configurations for question_data downloader
RUN_download_question_data = True
# Headers to send with request to https://algoexpert.io
REQUEST_HEADERS_FOR_ALGOEXPERT_SITE = {
"authorization": AUTH_KEY,
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9,bn;q=0.8",
"cache-control": "no-cache",
"content-type": "text/plain;charset=UTF-8",
"origin": "https://www.algoexpert.io",
"pragma": "no-cache",
"referer": "https://www.algoexpert.io/",
"sec-ch-ua": '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "Windows",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
}
DOWNLOAD_QUESTION_LIST = True # If previously downloaded then set False
# Question list endpoint
QUESTION_LIST_ENDPOINT = "https://prod.api.algoexpert.io/api/problems/v1/algoexpert/coding-questions/list"
QUESTION_LIST_FILE_NAME = 'question_list.json'
DOWNLOAD_QUESTION_DATA = True # If previously downloaded then set False
# Question metadata endpoint
QUESTION_DATA_ENDPOINT = "https://prod.api.algoexpert.io/api/problems/v1/algoexpert/coding-questions/get"
DOWNLOAD_QUESTION_TESTS = True # If previously downloaded then set False
# Question tests endpoint
QUESTION_TESTS_ENDPOINT = "https://prod.api.algoexpert.io/api/problems/v1/run_json_tests"
# Cooldown time between requests in seconds
COOLDOWN_TIME = 1
# Indentation spaces for formatting downloaded json responses
INDENTATION_SPACES = 2
# ================================================================
# Configurations for question_pdf downloader
RUN_download_question_pdf = True # If previously downloaded then set False
QUESTION_URL_PREFIX = "https://www.algoexpert.io/questions/"
TEMP_PDF_DOWNLOAD_DIR = pathlib.Path('./temp/')
TEMP_PDF_DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True)
# Required to download pdf using already logged in session
CHROME_USER_DATA_DIR = pathlib.Path("C:\\Users\\Iftek\\AppData\\Local\\Google\\Chrome\\User Data")
CHROME_SETTINGS_APPSTATE = "{\"version\":2,\"recentDestinations\":[{\"id\":\"Save as PDF\",\"origin\":\"local\",\"account\":\"\",\"capabilities\":{\"printer\":{\"color\":{\"option\":[{\"is_default\":true,\"type\":\"STANDARD_COLOR\",\"vendor_id\":\"2\"}]},\"media_size\":{\"option\":[{\"height_microns\":1189000,\"name\":\"ISO_A0\",\"width_microns\":841000,\"custom_display_name\":\"A0\"},{\"height_microns\":841000,\"name\":\"ISO_A1\",\"width_microns\":594000,\"custom_display_name\":\"A1\"},{\"height_microns\":594000,\"name\":\"ISO_A2\",\"width_microns\":420000,\"custom_display_name\":\"A2\"},{\"height_microns\":420000,\"name\":\"ISO_A3\",\"width_microns\":297000,\"custom_display_name\":\"A3\"},{\"height_microns\":297000,\"is_default\":true,\"name\":\"ISO_A4\",\"width_microns\":210000,\"custom_display_name\":\"A4\"},{\"height_microns\":210000,\"name\":\"ISO_A5\",\"width_microns\":148000,\"custom_display_name\":\"A5\"},{\"height_microns\":355600,\"name\":\"NA_LEGAL\",\"width_microns\":215900,\"custom_display_name\":\"Legal\"},{\"height_microns\":279400,\"name\":\"NA_LETTER\",\"width_microns\":215900,\"custom_display_name\":\"Letter\"},{\"height_microns\":431800,\"name\":\"NA_LEDGER\",\"width_microns\":279400,\"custom_display_name\":\"Tabloid\"}]},\"page_orientation\":{\"option\":[{\"type\":\"PORTRAIT\"},{\"type\":\"LANDSCAPE\"},{\"is_default\":true,\"type\":\"AUTO\"}]}},\"version\":\"1.0\"},\"displayName\":\"Save as PDF\",\"extensionId\":\"\",\"extensionName\":\"\",\"icon\":\"cr:insert-drive-file\"},{\"id\":\"Microsoft Print to PDF\",\"origin\":\"local\",\"account\":\"\",\"capabilities\":{\"printer\":{\"color\":{\"option\":[{\"is_default\":true,\"type\":\"STANDARD_COLOR\",\"vendor_id\":\"2\"},{\"type\":\"STANDARD_MONOCHROME\",\"vendor_id\":\"1\"}]},\"copies\":{\"default\":1,\"max\":1},\"dpi\":{\"option\":[{\"horizontal_dpi\":600,\"is_default\":true,\"vertical_dpi\":600}]},\"media_size\":{\"option\":[{\"custom_display_name\":\"Letter\",\"height_microns\":279400,\"name\":\"NA_LETTER\",\"vendor_id\":\"1\",\"width_microns\":215900},{\"custom_display_name\":\"Tabloid\",\"height_microns\":431800,\"name\":\"NA_LEDGER\",\"vendor_id\":\"3\",\"width_microns\":279400},{\"custom_display_name\":\"Legal\",\"height_microns\":355600,\"name\":\"NA_LEGAL\",\"vendor_id\":\"5\",\"width_microns\":215900},{\"custom_display_name\":\"Statement\",\"height_microns\":215900,\"name\":\"NA_INVOICE\",\"vendor_id\":\"6\",\"width_microns\":139700},{\"custom_display_name\":\"Executive\",\"height_microns\":266700,\"name\":\"NA_EXECUTIVE\",\"vendor_id\":\"7\",\"width_microns\":184100},{\"custom_display_name\":\"A3\",\"height_microns\":420000,\"name\":\"ISO_A3\",\"vendor_id\":\"8\",\"width_microns\":297000},{\"custom_display_name\":\"A4\",\"height_microns\":297000,\"is_default\":true,\"name\":\"ISO_A4\",\"vendor_id\":\"9\",\"width_microns\":210000},{\"custom_display_name\":\"A5\",\"height_microns\":210000,\"name\":\"ISO_A5\",\"vendor_id\":\"11\",\"width_microns\":148000},{\"custom_display_name\":\"B4 (JIS)\",\"height_microns\":364000,\"name\":\"JIS_B4\",\"vendor_id\":\"12\",\"width_microns\":257000},{\"custom_display_name\":\"B5 (JIS)\",\"height_microns\":257000,\"name\":\"JIS_B5\",\"vendor_id\":\"13\",\"width_microns\":182000}]},\"page_orientation\":{\"option\":[{\"is_default\":true,\"type\":\"PORTRAIT\"},{\"type\":\"LANDSCAPE\"},{\"type\":\"AUTO\"}]},\"supported_content_type\":[{\"content_type\":\"application/pdf\"}]},\"version\":\"1.0\"},\"displayName\":\"Microsoft Print to PDF\",\"extensionId\":\"\",\"extensionName\":\"\",\"icon\":\"print-preview:print\"}],\"isCssBackgroundEnabled\":true,\"customMargins\":{},\"dpi\":{\"horizontal_dpi\":600,\"is_default\":true,\"vertical_dpi\":600,\"name\":\"600 dpi\"},\"isHeaderFooterEnabled\":false,\"isLandscapeEnabled\":true,\"marginsType\":1,\"mediaSize\":{\"height_microns\":297000,\"is_default\":true,\"name\":\"ISO_A4\",\"width_microns\":210000,\"custom_display_name\":\"A4\"}}"
CHROME_PREFERENCES = {
'printing.print_preview_sticky_settings.appState': CHROME_SETTINGS_APPSTATE,
'savefile.default_directory': str(TEMP_PDF_DOWNLOAD_DIR.absolute())
}
LOAD_QUESTION_MAX_WAIT_TIME = 20
# Required to wait until the question statement is loaded
QUESTION_STATEMENT_XPATH = '//*[@id="root"]/div/div[6]/div[6]/div/div/div/div/div/div[2]/div[3]/div/div[2]/div'
# Time to wait to le the hints to expand
HINT_EXPAND_WAIT_TIME = 3.5
# ================================================================
# Configurations for question_solution_videos downloader
RUN_download_question_solution_videos = True # If previously downloaded then set False
ALLOWED_ORIGIN_FOR_VIDEOS = "https://www.algoexpert.io/"
REQUEST_HEADERS_FOR_VIMEO_SITE = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9,bn;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Host": "player.vimeo.com",
"Pragma": "no-cache",
"Referer": ALLOWED_ORIGIN_FOR_VIDEOS,
"sec-ch-ua": '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "Windows",
"Sec-Fetch-Dest": "iframe",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "cross-site",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36",
}
VIDEO_URLS_REGEX = re.compile(r"(?:\")(?P<url>https://vod-progressive.+?mp4)(?:\")(?:.+?)\"quality\":\"(?P<quality>.+?)\"", re.MULTILINE)
# ================================================================
# Configurations for practice_environment_builder
# Not good enough to generate testing code for complex questions
# only usable for questions that are functions
RUN_build_practice_environment = True
# Root directory path to build practice environment
PRACTICE_ENVIRONMENT_ROOT_DIR = pathlib.Path('./Practice/')
PRACTICE_ENVIRONMENT_ROOT_DIR.mkdir(parents=True, exist_ok=True)
PREFERRED_LANGUAGE_RESOURCE_KEY = "python"
PREFERRED_LANGUAGE_FILE_EXTENSION = "py"
# Note: Currently only builds environment for "python" language