From 965689df7a6ad94bd88b8d52e0a5001c9ce88798 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Sat, 15 Mar 2025 21:53:27 +0100 Subject: [PATCH] style: Run linter and fix code formatting in youtube.py --- personal_data/fetchers/youtube.py | 38 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/personal_data/fetchers/youtube.py b/personal_data/fetchers/youtube.py index 4b0a6c0..d4532d0 100644 --- a/personal_data/fetchers/youtube.py +++ b/personal_data/fetchers/youtube.py @@ -1,15 +1,17 @@ import csv import json -import subprocess import logging +import subprocess from dataclasses import dataclass + from personal_data.data import DeduplicateMode, Scraper logger = logging.getLogger(__name__) + @dataclass(frozen=True) class YoutubeFavoritesScraper(Scraper): - dataset_name: str = "youtube_favorites" + dataset_name: str = 'youtube_favorites' deduplicate_mode: DeduplicateMode = DeduplicateMode.BY_ALL_COLUMNS def fetch_data(self) -> list[dict]: @@ -20,7 +22,12 @@ class YoutubeFavoritesScraper(Scraper): try: # Replace 'YOUR_FAVORITES_ID' with your actual favorites playlist ID. result = subprocess.run( - ['yt-dlp', '--flat-playlist', '--dump-json', 'https://www.youtube.com/playlist?list=YOUR_FAVORITES_ID'], + [ + 'yt-dlp', + '--flat-playlist', + '--dump-json', + 'https://www.youtube.com/playlist?list=YOUR_FAVORITES_ID', + ], capture_output=True, check=True, text=True, @@ -28,7 +35,7 @@ class YoutubeFavoritesScraper(Scraper): videos = [json.loads(line) for line in result.stdout.splitlines()] return videos except Exception as e: - logger.error("Failed to fetch YouTube favorites: %s", e) + logger.error('Failed to fetch YouTube favorites: %s', e) raise def to_csv(self, videos: list[dict]) -> str: @@ -36,16 +43,19 @@ class YoutubeFavoritesScraper(Scraper): Convert the list of videos to CSV format. """ output = [] - headers = ["id", "title", "url", "upload_date"] + headers = ['id', 'title', 'url', 'upload_date'] output.append(headers) for video in videos: - output.append([ - video.get("id"), - video.get("title"), - video.get("url"), - video.get("upload_date"), - ]) + output.append( + [ + video.get('id'), + video.get('title'), + video.get('url'), + video.get('upload_date'), + ], + ) from io import StringIO + sio = StringIO() csv_writer = csv.writer(sio) csv_writer.writerows(output) @@ -54,7 +64,7 @@ class YoutubeFavoritesScraper(Scraper): def run(self) -> None: videos = self.fetch_data() csv_data = self.to_csv(videos) - logger.info("Fetched and converted %d videos to CSV", len(videos)) - with open("youtube_favorites.csv", "w", encoding="utf-8") as f: + logger.info('Fetched and converted %d videos to CSV', len(videos)) + with open('youtube_favorites.csv', 'w', encoding='utf-8') as f: f.write(csv_data) - logger.info("CSV file written to youtube_favorites.csv") + logger.info('CSV file written to youtube_favorites.csv')