replace prints with structlog.

This commit is contained in:
matt 2026-05-06 16:11:30 -07:00
parent ce66005bb3
commit c36a6a7f62
5 changed files with 29 additions and 6 deletions

View File

@ -12,6 +12,7 @@ dependencies = [
"pydantic>=2.0",
"pydantic-settings>=2.12.0",
"requests>=2.32.3",
"structlog>=25.5.0",
"yt-dlp>=2025.1.15",
]

View File

@ -3,6 +3,7 @@ from pathlib import Path
from typing import ClassVar
from pydantic_settings import CliImplicitFlag, CliPositionalArg
import structlog
import yt_dlp
from mutagen.easyid3 import EasyID3
from pydantic import Field, computed_field
@ -10,6 +11,8 @@ from pydantic import Field, computed_field
from music.dates import DateParse
from music.models import Command
log = structlog.get_logger()
def current_quarter() -> Path:
date = DateParse()
@ -71,3 +74,5 @@ class YtDownload(Command):
else:
new_filepath = base / Path(filename).name
os.rename(filename, new_filepath)
log.info("downloaded", path=str(new_filepath))

View File

@ -5,10 +5,13 @@ import subprocess
from pydantic import Field
import requests
import structlog
from music.dates import DateParse
from music.models import Command
log = structlog.get_logger()
class Source(str, Enum):
KEXP = "kexp"
@ -24,7 +27,7 @@ def current_quarter() -> Path:
def url_for_time(t) -> str:
default = "https://kexp-mp3-128.streamguys1.com/kexp128.mp3"
tz = t.strftime("%Y-%m-%dT%H:%M:%SZ")
print(f"getting archive: {t}")
log.info("getting archive", time=t)
check_url = (
f"https://api.kexp.org/get_streaming_url/?bitrate=128&timestamp={tz}&location=1"
)
@ -32,10 +35,10 @@ def url_for_time(t) -> str:
if response.status_code == 200:
found = response.json().get("sg-url")
if found is None:
print(f"error getting archive: {t}")
log.error("error getting archive", time=t)
return default
else:
print(f"error getting archive: {t}")
log.error("error getting archive", time=t, status=response.status_code)
return default
return found

View File

@ -3,11 +3,14 @@ from enum import Enum
from .paths import seasons
import random
import requests
import structlog
# import mpv
import tempfile
import os
log = structlog.get_logger()
class Stream(str, Enum):
KEXP = "kexp"
@ -18,7 +21,7 @@ class Stream(str, Enum):
def url_for_time(t) -> str:
default = "https://kexp-mp3-128.streamguys1.com/kexp128.mp3"
tz = t.strftime("%Y-%m-%dT%H:%M:%SZ")
print(f"getting archive: {t}")
log.info("getting archive", time=t)
check_url = (
f"https://api.kexp.org/get_streaming_url/?bitrate=128&timestamp={tz}&location=1"
)
@ -26,10 +29,10 @@ def url_for_time(t) -> str:
if response.status_code == 200:
found = response.json().get("sg-url")
if found is None:
print(f"error getting archive: {t}")
log.error("error getting archive", time=t)
return default
else:
print(f"error getting archive: {t}")
log.error("error getting archive", time=t, status=response.status_code)
return default
return found

11
uv.lock
View File

@ -143,6 +143,7 @@ dependencies = [
{ name = "pydantic" },
{ name = "pydantic-settings" },
{ name = "requests" },
{ name = "structlog" },
{ name = "yt-dlp" },
]
@ -154,6 +155,7 @@ requires-dist = [
{ name = "pydantic", specifier = ">=2.0" },
{ name = "pydantic-settings", specifier = ">=2.12.0" },
{ name = "requests", specifier = ">=2.32.3" },
{ name = "structlog", specifier = ">=25.5.0" },
{ name = "yt-dlp", specifier = ">=2025.1.15" },
]
@ -294,6 +296,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/d7/8e/7540e8a2036f79a125c1d2ebadf69ed7901608859186c856fa0388ef4197/requests-2.33.1-py3-none-any.whl", hash = "sha256:4e6d1ef462f3626a1f0a0a9c42dd93c63bad33f9f1c1937509b8c5c8718ab56a", size = 64947, upload-time = "2026-03-30T16:09:13.83Z" },
]
[[package]]
name = "structlog"
version = "25.5.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/ef/52/9ba0f43b686e7f3ddfeaa78ac3af750292662284b3661e91ad5494f21dbc/structlog-25.5.0.tar.gz", hash = "sha256:098522a3bebed9153d4570c6d0288abf80a031dfdb2048d59a49e9dc2190fc98", size = 1460830, upload-time = "2025-10-27T08:28:23.028Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/a8/45/a132b9074aa18e799b891b91ad72133c98d8042c70f6240e4c5f9dabee2f/structlog-25.5.0-py3-none-any.whl", hash = "sha256:a8453e9b9e636ec59bd9e79bbd4a72f025981b3ba0f5837aebf48f02f37a7f9f", size = 72510, upload-time = "2025-10-27T08:28:21.535Z" },
]
[[package]]
name = "typing-extensions"
version = "4.15.0"