From d352ebbc17bac3ab7d4372e0976096008ac69750 Mon Sep 17 00:00:00 2001 From: pta Date: Thu, 18 Apr 2024 18:24:31 -0400 Subject: [PATCH 1/2] Document yt-dlp dependency and update docstring --- README.md | 1 + src/WeatherNews.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9494df0..f4fd857 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ using DataFrames s |> DataFrame ``` +Install `yt-dlp`. Optionally install `jq` for pretty-printing and exploring json on the command line. ## Scripts diff --git a/src/WeatherNews.jl b/src/WeatherNews.jl index 571a9e3..c41f619 100644 --- a/src/WeatherNews.jl +++ b/src/WeatherNews.jl @@ -108,7 +108,7 @@ function iswnl(title) end """ -Find the current live video's id and update the schedule table if a corresponding row can be found. +Fetch upcoming live videos' IDs and update the schedule table's corresponding rows. # Examples ```jldoctest From 2d1c05baa415482570eb4cf576b552a3ba2e3e65 Mon Sep 17 00:00:00 2001 From: pta Date: Fri, 19 Apr 2024 18:21:28 -0400 Subject: [PATCH 2/2] Start recording view counts in schedule table --- sql/05.view_count.sql | 2 ++ src/WeatherNews.jl | 12 ++++++++++-- src/db.jl | 11 +++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 sql/05.view_count.sql diff --git a/sql/05.view_count.sql b/sql/05.view_count.sql new file mode 100644 index 0000000..093aea5 --- /dev/null +++ b/sql/05.view_count.sql @@ -0,0 +1,2 @@ +ALTER TABLE schedule + ADD COLUMN view_count INTEGER; diff --git a/src/WeatherNews.jl b/src/WeatherNews.jl index c41f619..16650c5 100644 --- a/src/WeatherNews.jl +++ b/src/WeatherNews.jl @@ -120,9 +120,17 @@ function update_schedule_with_live_video(db) for v in vids if iswnl(v[:title]) jst = wnl_title_to_jst(v[:title]) - DB.update_schedule_with_video(db, string(jst), v[:id]) + views = + if v[:live_status] == "was_live" + v[:view_count] + elseif v[:live_status] == "is_live" + v[:concurrent_view_count] + else # "is_upcoming" + 0 + end + DB.update_schedule_with_video(db, string(jst), v[:id], views) if hour(jst) == 23 - DB.update_schedule_with_video(db, string(jst + Hour(1)), v[:id]) + DB.update_schedule_with_video(db, string(jst + Hour(1)), v[:id], views) end else continue diff --git a/src/db.jl b/src/db.jl index 76f03c4..313e443 100644 --- a/src/db.jl +++ b/src/db.jl @@ -91,14 +91,17 @@ function find_schedule_by_jst(db, jst) end """ -Update a schedule row with its `video_id`. +Update a schedule row with its `video_id` and `view_count`. This function is for WN videos only, and it should skip over au PAY videos. """ -function update_schedule_with_video(db, jst, video_id) +function update_schedule_with_video(db, jst, video_id, view_count) try - sql_update = "UPDATE schedule SET video_id = ? WHERE jst = ? AND segment_id NOT IN (8)" - return DBInterface.execute(db, sql_update, [video_id, jst]) + sql_update = """ + UPDATE schedule SET video_id = ?, view_count = ? + WHERE jst = ? AND segment_id NOT IN (8); + """ + return DBInterface.execute(db, sql_update, [video_id, view_count, jst]) catch e @debug e return e