-
-
Save doekman/121cc8e71368aaf2396f97b232b58f2a to your computer and use it in GitHub Desktop.
Take a text-file with links, and produce a MarkDown bulleted list with links, and their title.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| brew install uv | |
| # Now uses `uv` to run | |
| run: ./enrich_links.py # Run a test, demonstrating the library |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env -S uv run | |
| # /// script | |
| # requires-python = ">=3.10" | |
| # dependencies = ["requests", "bs4"] | |
| # /// | |
| import requests | |
| from bs4 import BeautifulSoup | |
| filename = './links.txt' | |
| with open(filename) as file_handle: | |
| while line := file_handle.readline(): | |
| url = line.strip() | |
| # Check for comments | |
| if url.startswith('#'): | |
| continue | |
| try: | |
| reqs = requests.get(url) | |
| if reqs.ok: | |
| # using the BeautifulSoup module | |
| soup = BeautifulSoup(reqs.text, 'html.parser') | |
| if soup.title is None: | |
| title = soup.find('title') | |
| if title is None: | |
| title = f"{url} (no title)" | |
| else: | |
| title = soup.title.string | |
| title = title.strip() | |
| print(f"- [{title.replace('|', r'\|')}]({url})") | |
| else: | |
| print(f"- [{url}]({url}) -- {reqs.status_code} {reqs.reason}") | |
| except Exception as e: | |
| print(f"- [{url}]({url}) -- (exception when retrieving: {str(e)})") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #provide your own | |
| https://lekkerder.nl/groentekwekerij-noordlaren | |
| https://pivot-to-ai.com/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment