Skip to content

script to update talks yaml files #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions scripts/dump_talks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This script will query the API and dump the speakers data to a YAML file
# speaker data can we updated in production, this is a way to sync our seed data to reflect as closely as possible the prod environment

require "net/http"
require "json"
require "yaml"

API_ENDPOINT = "https://www.rubyvideo.dev/talks.json"
# API_ENDPOINT = "http://localhost:3000/talks.json"
# OUTPUT_FILE = "data/talks.yml"

def fetch_talks
talks = []
current_page = 1

loop do
uri = URI("#{API_ENDPOINT}?page=#{current_page}")
response = Net::HTTP.get(uri)
parsed_response = JSON.parse(response)

talks.concat(parsed_response["talks"].map { |talk| talk.slice("slug", "title", "video_id", "video_provider") })
current_page += 1
break if parsed_response.dig("pagination", "next_page").nil?
end

talks
end

# def save_to_yaml(data)
# File.write(OUTPUT_FILE, data.to_yaml)
# end

puts talks_data = fetch_talks
# save_to_yaml(talks_data)

# puts "Talks data saved to #{OUTPUT_FILE}"

puts "formating with Prettier..."

# system("yarn prettier --write #{OUTPUT_FILE}")

puts "Done!"
Loading