cool project :)
on github you can get a file's code via raw.githubusercontent.com which can be useful
# /// script
# requires-python = ">=3.8"
# dependencies = ["requests", "bs4"]
# ///
import requests
from bs4 import BeautifulSoup
import html
def extract_tangled_code(url: str) -> str:
if not (code_divs := BeautifulSoup(requests.get(url).text, "html.parser").select("div.whitespace-pre")):
return "no code divs :/"
return "\n".join(html.unescape(div.get_text(strip=False)) for div in code_divs)
print(
extract_tangled_code(
"https://tangled.sh/@alternatebuild.dev/mcpsrvrs/blob/main/fetch.py"
)
)
lmk if there's a way I'm missing or if this is out of scope - ty!