Skip to content

Instantly share code, notes, and snippets.

@jefftriplett
Last active August 22, 2024 03:31
Show Gist options
  • Save jefftriplett/4779b59ec0572e630aac64779f0559d5 to your computer and use it in GitHub Desktop.
Save jefftriplett/4779b59ec0572e630aac64779f0559d5 to your computer and use it in GitHub Desktop.
An example of how to process a folder of json files that I pulled from YouTube using a bunch of python technology like: uv, duckdb, rich, and typer.
#
# To run this application, use:
# uv run demo-duckdb.py
#
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "duckdb",
# "rich",
# "typer",
# ]
# ///
import duckdb
import typer
from rich import print
def main():
result = duckdb.sql("SELECT id,snippet FROM read_json('json/*.json')").fetchall()
for row in result:
id, snippet = row
print("-" * 80)
print(f"{id=}")
print(f"{snippet['channelTitle']=}")
print(f"{snippet['title']=}")
print(f"{snippet['publishedAt']=}")
print(snippet["description"])
print(snippet["thumbnails"].get("maxres") or snippet.get("standard"))
print()
if __name__ == "__main__":
typer.run(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment