-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_docs.py
More file actions
317 lines (282 loc) · 9.96 KB
/
Copy pathfetch_docs.py
File metadata and controls
317 lines (282 loc) · 9.96 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import os
import io
import zipfile
import urllib.request
import urllib.error
import ssl
# Fix for macOS SSL Handshake errors
ssl._create_default_https_context = ssl._create_unverified_context
DATA_DIR = "./data"
MEMORIES_DIR = "./memories"
# Branch candidates to try if main fails
BRANCH_CANDIDATES = ["main", "master", "trunk", "development", "next", "v2"]
DOC_SOURCES = {
# --- 1. NNg & UX Heuristics / Articles ---
"Laws_of_UX": {
"repo": "keysjoao/laws-of-ux-skills",
"target_folder": "data/ux_heuristics",
"subpath": ""
},
"UX_Craft_and_Principles": {
"repo": "nexu-io/open-design",
"target_folder": "data/ux_heuristics",
"subpath": "craft/"
},
# --- 2. Public UX & Programming Books ---
"Free_Programming_Books": {
"repo": "EbookFoundation/free-programming-books",
"target_folder": "data/books_programming",
"subpath": "books/"
},
"Design_Books_Catalog": {
"repo": "robleto/design-books",
"target_folder": "data/books_ux",
"subpath": ""
},
"Atomic_Design_Book": {
"repo": "bradfrost/atomic-design",
"target_folder": "data/graphic_design",
"subpath": ""
},
"Awesome_Design_Systems": {
"repo": "alialaa/awesome-design-systems",
"target_folder": "data/graphic_design",
"subpath": ""
},
# --- 3. Figma & Miro Developer Platform Docs ---
"Figma_Plugin_Docs": {
"repo": "figma/plugin-docs",
"target_folder": "data/figma_docs",
"subpath": ""
},
"Figma_Community_Resources": {
"repo": "figma/community-resources",
"target_folder": "data/figma_docs",
"subpath": ""
},
"Miro_Developer_Examples": {
"repo": "miroapp/app-examples",
"target_folder": "data/miro_docs",
"subpath": ""
},
# --- 4. Machine Learning ---
"Scikit_Learn_ML": {
"repo": "scikit-learn/scikit-learn",
"target_folder": "data/machine_learning",
"subpath": "doc/modules/"
},
"FastAI_Deep_Learning_Book": {
"repo": "fastai/fastbook",
"target_folder": "data/machine_learning",
"subpath": ""
},
"PyTorch_Tutorials": {
"repo": "pytorch/tutorials",
"target_folder": "data/machine_learning",
"subpath": "beginner_source/"
},
# --- 5. UX Design Materials (PUCRS / General) ---
"UX_Best_Practices": {
"repo": "mendix/docs",
"target_folder": "data/pucrs_ux",
"subpath": "content/en/docs/howto/front-end/"
},
# --- 6. Web Components (HTML, CSS, JavaScript) ---
"MDN_Web_Docs": {
"repo": "mdn/content",
"target_folder": "data/mdn_web_docs",
"subpaths": [
"files/en-us/web/javascript/",
"files/en-us/web/css/",
"files/en-us/web/html/",
"files/en-us/web/api/"
]
},
"Modern_JS_Tutorial": {
"repo": "javascript-tutorial/en.javascript.info",
"target_folder": "data/javascript_expert",
"subpath": ""
},
"TypeScript_Docs": {
"repo": "microsoft/TypeScript-website",
"target_folder": "data/typescript_docs",
"subpath": "packages/documentation/copy/en/"
},
# --- 7. Swift, SwiftUI, Metal & Apple HIG ---
"Swift_Book": {
"repo": "apple/swift-book",
"target_folder": "data/swift_docs",
"subpath": "TSPL.docc/"
},
"Swift_Evolution": {
"repo": "apple/swift-evolution",
"target_folder": "data/swift_docs",
"subpath": "proposals/"
},
"Awesome_SwiftUI_Reference": {
"repo": "alexiscreuzot/awesome-swiftui",
"target_folder": "data/swift_docs",
"subpath": ""
},
# --- 8. Semantic Versioning ---
"Semantic_Versioning": {
"repo": "semver/semver.org",
"target_folder": "data/semver",
"subpath": ""
},
# --- 9. Storybook Implementation ---
"Storybook_Docs": {
"repo": "storybookjs/storybook",
"target_folder": "data/storybook",
"subpath": "docs/"
},
"Storybook_Tutorials": {
"repo": "storybookjs/tutorials",
"target_folder": "data/storybook",
"subpath": "content/"
},
# --- 10. Python & Framework Architecture ---
"Python_Tutorials": {
"repo": "python/cpython",
"target_folder": "data/python_docs",
"subpath": "Doc/tutorial/"
},
"FastAPI_Docs": {
"repo": "fastapi/fastapi",
"target_folder": "data/python_expert",
"subpath": "docs/en/docs/"
},
"Python_Design_Patterns": {
"repo": "faif/python-patterns",
"target_folder": "data/python_expert",
"subpath": ""
},
# --- 11. Computer Science & Architecture ---
"OSSU_Computer_Science": {
"repo": "ossu/computer-science",
"target_folder": "data/computer_science",
"subpath": ""
},
"CS_Interview_University": {
"repo": "jwasham/coding-interview-university",
"target_folder": "data/computer_science",
"subpath": ""
},
"System_Design_Primer": {
"repo": "donnemartin/system-design-primer",
"target_folder": "data/system_architecture",
"subpath": ""
},
"Node_Web_Best_Practices": {
"repo": "goldbergyoni/nodebestpractices",
"target_folder": "data/web_best_practices",
"subpath": ""
},
# --- 12. Accessibility & WCAG ---
"WCAG_Standards": {
"repo": "w3c/wcag",
"target_folder": "data/wcag",
"subpath": "guidelines/"
},
"A11Y_Project": {
"repo": "a11yproject/a11yproject.com",
"target_folder": "data/wcag",
"subpath": "src/content/"
},
# --- 13. IDE & CLI Tools ---
"VS_Code_Docs": {
"repo": "microsoft/vscode-docs",
"target_folder": "data/vscode_docs",
"subpath": "docs/"
},
"GitHub_Official_Docs": {
"repo": "github/docs",
"target_folder": "data/github_docs",
"subpath": "content/get-started/"
},
"GitHub_CLI_Docs": {
"repo": "cli/cli",
"target_folder": "data/github_cli",
"subpath": "docs/"
}
}
def download_and_extract(name, config):
target = config["target_folder"]
if os.path.exists(target) and os.listdir(target):
print(f"⏭️ {name} docs already exist in {target}. Skipping.")
return
print(f"\n📦 Downloading official docs for {name} ({config['repo']})...")
zip_data = None
successful_branch = None
repo_name = config["repo"].split("/")[-1]
# Try downloading across branch candidates
for branch in BRANCH_CANDIDATES:
url = f"https://codeload.github.com/{config['repo']}/zip/refs/heads/{branch}"
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
try:
with urllib.request.urlopen(req) as response:
zip_data = response.read()
successful_branch = branch
break
except urllib.error.HTTPError as e:
if e.code == 404:
continue
print(f"⚠️ Network error for {name} on branch {branch}: {e}")
except Exception as e:
continue
if not zip_data:
print(f"❌ Failed to fetch {name}: Repository or branches not found.")
return
print(f"⚡ Extracting {name} (branch: '{successful_branch}') to {target}...")
# Base prefix inside zip file
zip_root = f"{repo_name}-{successful_branch}/"
try:
with zipfile.ZipFile(io.BytesIO(zip_data)) as z:
count = 0
for file_info in z.infolist():
if file_info.is_dir():
continue
# Build filter prefixes
if "subpaths" in config:
prefixes = [f"{zip_root}{p}" for p in config["subpaths"]]
elif config.get("subpath"):
prefixes = [f"{zip_root}{config['subpath']}"]
else:
prefixes = [zip_root]
is_target = any(file_info.filename.startswith(p) for p in prefixes)
if is_target and file_info.filename.endswith(('.md', '.mdx', '.txt', '.json')):
# Strip the zip root folder prefix to maintain relative directory structure
relative_path = file_info.filename[len(zip_root):]
out_path = os.path.join(target, relative_path)
os.makedirs(os.path.dirname(out_path), exist_ok=True)
with z.open(file_info) as source, open(out_path, "wb") as target_file:
target_file.write(source.read())
count += 1
print(f"✅ Saved {count} documentation files for {name}.")
except Exception as e:
print(f"❌ Failed to extract {name}: {e}")
def prepare_manual_folders():
"""Creates directories for personal PDFs and user profile memories."""
folders = [
"./data/nng_pdfs",
"./data/pucrs_ux_pdfs",
"./data/custom_books",
"./memories"
]
for folder in folders:
os.makedirs(folder, exist_ok=True)
bio_path = os.path.join(MEMORIES_DIR, "lio_profile.md")
if not os.path.exists(bio_path):
with open(bio_path, "w", encoding="utf-8") as f:
f.write("# Category: Lio Profile & Preferences\n\n")
f.write("- [2026-07-30] Lio's birthday is November 27, 1997.\n")
f.write("- [2026-07-30] Lio is an M4 MacBook Air user developing Harvey local AI.\n")
if __name__ == "__main__":
os.makedirs(DATA_DIR, exist_ok=True)
os.makedirs(MEMORIES_DIR, exist_ok=True)
prepare_manual_folders()
print("🚀 Starting documentation download script...")
for name, config in DOC_SOURCES.items():
download_and_extract(name, config)
print("\n🎉 All public documentation checked and downloaded!")
print("💡 Next step: Run 'python ingest.py' to process the new files.")