From 5e39db08f49228103e5764f66b931dec6727d82e Mon Sep 17 00:00:00 2001 From: Adrien Poly Date: Mon, 27 Jan 2025 22:48:35 +0100 Subject: [PATCH] wip --- scripts/dump_talks.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 scripts/dump_talks.rb diff --git a/scripts/dump_talks.rb b/scripts/dump_talks.rb new file mode 100644 index 000000000..ad84783fa --- /dev/null +++ b/scripts/dump_talks.rb @@ -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!"