Skip to content

Instantly share code, notes, and snippets.

@scottstanie
Last active November 19, 2023 00:30
Show Gist options
  • Save scottstanie/5ac7e53ba99bf95add715710d8d4b617 to your computer and use it in GitHub Desktop.
Save scottstanie/5ac7e53ba99bf95add715710d8d4b617 to your computer and use it in GitHub Desktop.
Daily tao in your terminal
#!/usr/bin/env python
# pip install requests rich beautifulsoup4
import sys
import requests
from bs4 import BeautifulSoup
from rich.console import Console
from rich.panel import Panel
URL = "https://dailytao.org/"
console = Console()
def fetch_tao_content():
response = requests.get(URL)
response.raise_for_status()
soup = BeautifulSoup(response.content, "html.parser")
# Get the poem content
poem_elements = []
fineprint_content = ""
for current_element in soup.find("p"):
if current_element.name == "div":
fineprint_content = current_element.text
break
if current_element.name == "br":
continue
poem_elements.append(current_element.text.strip())
poem_content = "\n".join(poem_elements)
return poem_content, fineprint_content
def display_with_rich(poem_content, fineprint_content):
formatted_content = f"{poem_content}\n\n[italic white]{fineprint_content}[/italic white]"
poem_panel = Panel(formatted_content, title="Daily Tao", border_style="green")
console.print(poem_panel)
if __name__ == "__main__":
poem_content, fineprint_content = fetch_tao_content()
if len(sys.argv) > 1 and sys.argv[-1] == '--raw':
print(poem_content)
else:
display_with_rich(poem_content, fineprint_content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment