-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathmake-tutorials-md.py
More file actions
54 lines (40 loc) · 1.26 KB
/
make-tutorials-md.py
File metadata and controls
54 lines (40 loc) · 1.26 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
import os
import requests
import xml.etree.ElementTree as ET
from urllib.parse import urlparse
from pathlib import Path
# Configuration
RSS_FEED_URL = "https://www.pyopensci.org/python-package-guide/tutorials.rss"
OUTPUT_DIR = Path("_tutorials")
OUTPUT_DIR.mkdir(exist_ok=True)
def slug_from_url(url):
"""Extract filename from URL and remove `.html`"""
return Path(urlparse(url).path).stem
def create_markdown_file(title, excerpt, link):
slug = slug_from_url(link)
filename = OUTPUT_DIR / f"{slug}.md"
content = f"""---
title: "{title.strip()}"
excerpt: "{excerpt.strip()}"
link: {link}
btn_label: View Tutorial
btn_class: btn--success btn--large
---
"""
filename.write_text(content, encoding="utf-8")
print(f"✅ Created: {filename}")
def main():
print("🔍 Fetching RSS feed...")
resp = requests.get(RSS_FEED_URL)
resp.raise_for_status()
root = ET.fromstring(resp.content)
items = root.findall(".//item")
for item in items:
title = item.findtext("title")
link = item.findtext("link")
excerpt = item.findtext("description")
if title and link and excerpt:
create_markdown_file(title, excerpt, link)
print("🎉 All tutorials processed!")
if __name__ == "__main__":
main()