Merge pull request 'Mention yt-dlp in README and start recording view counts' (#10) from pta/WeatherNews.jl:main into main

Reviewed-on: #10
This commit is contained in:
gg 2024-04-23 02:51:25 +00:00
commit 4fe3e10656
4 changed files with 21 additions and 7 deletions

View File

@ -37,6 +37,7 @@ using DataFrames
s |> DataFrame s |> DataFrame
``` ```
Install `yt-dlp`. Optionally install `jq` for pretty-printing and exploring json on the command line.
## Scripts ## Scripts

2
sql/05.view_count.sql Normal file
View File

@ -0,0 +1,2 @@
ALTER TABLE schedule
ADD COLUMN view_count INTEGER;

View File

@ -108,7 +108,7 @@ function iswnl(title)
end 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 # Examples
```jldoctest ```jldoctest
@ -120,9 +120,17 @@ function update_schedule_with_live_video(db)
for v in vids for v in vids
if iswnl(v[:title]) if iswnl(v[:title])
jst = wnl_title_to_jst(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 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 end
else else
continue continue

View File

@ -91,14 +91,17 @@ function find_schedule_by_jst(db, jst)
end 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. 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 try
sql_update = "UPDATE schedule SET video_id = ? WHERE jst = ? AND segment_id NOT IN (8)" sql_update = """
return DBInterface.execute(db, sql_update, [video_id, jst]) 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 catch e
@debug e @debug e
return e return e