Skip to content

Commit 29e703f

Browse files
Automate show updates
1 parent 335ccc7 commit 29e703f

File tree

5 files changed

+201
-12
lines changed

5 files changed

+201
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
.env
22
_build/*
3+
4+
# Not needed in repository
5+
settings.yml.backup.*

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,27 @@
66

77
## Screenshots
88

9-
![screenshot](assets/screenshot.png)
9+
![screenshot](assets/screenshot.png)
10+
11+
## Development
12+
13+
### Updating Show Options
14+
15+
The show options in `src/settings.yml` can be automatically updated using the included script:
16+
17+
```bash
18+
./bin/update_shows
19+
```
20+
21+
This script:
22+
1. Fetches the latest show data from `https://producerplayer.services.pbskids.org/show-tracking`
23+
2. Creates a backup of the current `settings.yml` file
24+
3. Updates the `pbs_kids_show_id` field options with the latest shows as key-value pairs (`title: slug`)
25+
4. Sorts shows alphabetically by title
26+
5. Saves the updated settings
27+
28+
The script automatically creates a timestamped backup of the original settings file before making changes. Backups are stored in the same directory as the settings file with the format `settings.yml.backup.YYYYMMDD_HHMMSS`.
29+
30+
**Requirements:**
31+
- Ruby (built-in libraries only)
32+
- Internet connection to fetch data from PBS Kids API

bin/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# PBS Kids Show Options Updater
2+
3+
This script automatically updates the show options in `src/settings.yml` by fetching the latest show data from the PBS Kids API.
4+
5+
## Usage
6+
7+
From the project root directory:
8+
9+
```bash
10+
./bin/update_shows
11+
```
12+
13+
## What it does
14+
15+
1. Fetches the latest show data from `https://producerplayer.services.pbskids.org/show-tracking`
16+
2. Creates a backup of the current `settings.yml` file
17+
3. Updates the `pbs_kids_show_id` field options with the latest shows
18+
4. Sorts shows alphabetically by title
19+
5. Saves the updated settings
20+
21+
## Backup
22+
23+
The script automatically creates a timestamped backup of the original settings file before making changes. Backups are stored in the same directory as the settings file with the format:
24+
25+
```
26+
settings.yml.backup.YYYYMMDD_HHMMSS
27+
```
28+
29+
## Dependencies
30+
31+
- Ruby (built-in libraries only)
32+
- Internet connection to fetch data from PBS Kids API
33+
34+
## Error Handling
35+
36+
The script includes error handling for:
37+
- Network failures when fetching API data
38+
- JSON parsing errors
39+
- File I/O errors
40+
- Missing settings file or fields
41+
42+
If any error occurs, the script will exit with an error message and will not modify the settings file.

bin/update_shows

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'json'
4+
require 'net/http'
5+
require 'uri'
6+
require 'yaml'
7+
require 'fileutils'
8+
9+
# Configuration
10+
API_URL = 'https://producerplayer.services.pbskids.org/show-tracking'
11+
SETTINGS_FILE = File.join(File.dirname(__FILE__), '..', 'src', 'settings.yml')
12+
13+
def fetch_show_data
14+
puts "Fetching show data from PBS Kids API..."
15+
16+
uri = URI(API_URL)
17+
response = Net::HTTP.get_response(uri)
18+
19+
unless response.is_a?(Net::HTTPSuccess)
20+
puts "Error: Failed to fetch data from API. Status: #{response.code}"
21+
exit 1
22+
end
23+
24+
JSON.parse(response.body)
25+
rescue JSON::ParserError => e
26+
puts "Error: Failed to parse JSON response - #{e.message}"
27+
exit 1
28+
rescue StandardError => e
29+
puts "Error: Failed to fetch data - #{e.message}"
30+
exit 1
31+
end
32+
33+
def load_settings
34+
puts "Loading current settings..."
35+
36+
unless File.exist?(SETTINGS_FILE)
37+
puts "Error: Settings file not found at #{SETTINGS_FILE}"
38+
exit 1
39+
end
40+
41+
YAML.load_file(SETTINGS_FILE)
42+
rescue StandardError => e
43+
puts "Error: Failed to load settings file - #{e.message}"
44+
exit 1
45+
end
46+
47+
def format_show_options(shows)
48+
puts "Formatting show options..."
49+
50+
# Sort shows alphabetically by title
51+
sorted_shows = shows.sort_by { |show| show['title'] }
52+
53+
# Format as YAML array of hash entries
54+
sorted_shows.map do |show|
55+
{ show['title'] => show['slug'] }
56+
end
57+
end
58+
59+
def update_settings(settings, new_options)
60+
puts "Updating settings with new show options..."
61+
62+
# Find the PBS Kids show field
63+
pbs_kids_field = settings['custom_fields'].find { |field| field['keyname'] == 'pbs_kids_show_id' }
64+
65+
unless pbs_kids_field
66+
puts "Error: Could not find pbs_kids_show_id field in settings"
67+
exit 1
68+
end
69+
70+
# Update the options
71+
pbs_kids_field['options'] = new_options
72+
73+
settings
74+
end
75+
76+
def save_settings(settings)
77+
puts "Saving updated settings..."
78+
79+
# Create a backup
80+
backup_file = "#{SETTINGS_FILE}.backup.#{Time.now.strftime('%Y%m%d_%H%M%S')}"
81+
FileUtils.cp(SETTINGS_FILE, backup_file)
82+
puts "Backup created: #{backup_file}"
83+
84+
# Save the updated settings
85+
File.open(SETTINGS_FILE, 'w') do |file|
86+
file.write(settings.to_yaml)
87+
end
88+
89+
puts "Settings updated successfully!"
90+
rescue StandardError => e
91+
puts "Error: Failed to save settings - #{e.message}"
92+
exit 1
93+
end
94+
95+
def main
96+
puts "PBS Kids Show Options Updater"
97+
puts "=============================="
98+
99+
# Fetch latest show data
100+
shows = fetch_show_data
101+
puts "Found #{shows.length} shows"
102+
103+
# Load current settings
104+
settings = load_settings
105+
106+
# Format new options
107+
new_options = format_show_options(shows)
108+
109+
# Update settings
110+
updated_settings = update_settings(settings, new_options)
111+
112+
# Save updated settings
113+
save_settings(updated_settings)
114+
115+
puts "Update completed successfully!"
116+
puts "Updated #{new_options.length} show options"
117+
end
118+
119+
# Run the script
120+
main if __FILE__ == $0

src/settings.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ polling_url: |
88
https://producerplayer.services.pbskids.org/show-list/?available=public&shows={{ pbs_kids_show_id }}&sort=-encored_on&type=full_length&page=1
99
https://producerplayer.services.pbskids.org/show-tracking
1010
polling_headers: content-type=application/json
11-
polling_body:
11+
polling_body:
1212
id: 110655
1313
custom_fields:
1414
- keyname: author_bio
@@ -27,9 +27,9 @@ custom_fields:
2727
- Alma's Way: almas-way
2828
- Arthur: arthur
2929
- Brambletown: brambletown
30-
- Carl the Collector: carl-the-collector
3130
- 'CET Parents ': cet-parents
3231
- CET/ThinkTV Education: cetthinktv-education
32+
- Carl the Collector: carl-the-collector
3333
- City Island: city-island
3434
- Clifford the Big Red Dog: clifford-big-red-dog
3535
- Clifford's Puppy Days: cliffords-puppy-days
@@ -42,12 +42,11 @@ custom_fields:
4242
- Donkey Hodie: donkey-hodie
4343
- Dot's Spot: dots-spot
4444
- Elinor Wonders Why: elinor-wonders-why
45+
- FETCH! with Ruff Ruffman: fetch-with-ruff-ruffman
4546
- Family Math: family-math
4647
- Family Math en Español: family-math-en-espanol
47-
- FETCH! with Ruff Ruffman: fetch-with-ruff-ruffman
4848
- Fizzy's Lunch Lab: fizzys-lunch-lab
4949
- Hero Elementary: hero-elementary
50-
- 'iQ: smartparent': iq-smartparent
5150
- Jamming On the Job: jamming-on-the-job
5251
- Jelly, Ben & Pogo: jelly-ben-pogo
5352
- Keyshawn Solves It: keyshawn-solves-it
@@ -58,8 +57,8 @@ custom_fields:
5857
- Martha Speaks: martha-speaks
5958
- Maya & Miguel: maya-miguel
6059
- Mecha Builders: mecha-builders
61-
- Mega Wow: mega-wow
6260
- Meet the Helpers: meet-helpers
61+
- Mega Wow: mega-wow
6362
- Milo: milo
6463
- Mister Rogers' Neighborhood: mister-rogers
6564
- Molly of Denali: molly-of-denali
@@ -68,36 +67,38 @@ custom_fields:
6867
- Odd Squad: odd-squad
6968
- OddTube: odd-tube
7069
- Oh Noah!: oh-noah
71-
- Parent Hacks: parent-hacks
72-
- Parentalogic: parentalogic
73-
- Parenting Minutes: parenting-minutes
7470
- PBS KIDS: pbs-kids
7571
- PBS KIDS Rocks!: pbs-kids-rocks
7672
- PBS KIDS Talk About: pbs-kids-talk-about
7773
- 'PBS KIDS: Activity Challenge': pbs-kids-activity-challenge
7874
- 'PBS KIDS: Get Moving': pbs-kids-get-moving
75+
- PBS Western Reserve Educational Productions: western-reserve-public-media-educational-productions
76+
- Parent Hacks: parent-hacks
77+
- Parentalogic: parentalogic
78+
- Parenting Minutes: parenting-minutes
7979
- Peg + Cat: peg
8080
- Phoebe & Jay: phoebe-jay
8181
- Pinkalicious & Peterrific: pinkalicious-and-peterrific
8282
- Plum Landing: plum-landing
8383
- Ready Jet Go: ready-jet-go
8484
- Rocket Saves the Day: rocket-saves-the-day
8585
- Rosie's Rules: rosies-rules
86-
- Scribbles and Ink: scribbles-and-ink
86+
- SUPER WHY!: super-why
8787
- SciGirls: scigirls
88+
- Scribbles and Ink: scribbles-and-ink
8889
- Search It Up!: search-it-up
8990
- Sesame Street: sesame-street
9091
- Sid the Science Kid: sid-science-kid
9192
- Skillsville: skillsville
9293
- Splash and Bubbles: splash-and-bubbles
93-
- SUPER WHY!: super-why
9494
- Super Why's Comic Book Adventures: super-whys-comic-book-adventures
9595
- The Cat in the Hat: cat-in-the-hat
9696
- The Not-Too-Late Show with Elmo: not-too-late-show-elmo
9797
- The Ruff Ruffman Show: ruff-ruffman-show
9898
- Through the Woods: through-woods
9999
- Tiny Time Travel: tiny-time-travel
100100
- Together We Can: together-we-can
101+
- WOSU Specials: wosu-specials
101102
- Weather Hunters: weather-hunters
102103
- What Can You Become?: what-can-you-become
103104
- What's Good?: whats-good
@@ -106,8 +107,8 @@ custom_fields:
106107
- Word of the Week: word-of-the-week
107108
- WordGirl: wordgirl
108109
- Work It Out Wombats!: work-it-out-wombats
109-
- WOSU Specials: wosu-specials
110110
- Xavier Riddle and the Secret Museum: xavier-riddle-and-secret-museum
111111
- You, Me, Community: you-me-community
112+
- 'iQ: smartparent': iq-smartparent
112113
name: PBS Kids
113114
refresh_interval: 1440

0 commit comments

Comments
 (0)