Skip to content

Instantly share code, notes, and snippets.

Last active Nov 12, 2018
What would you like to do?
require "json"
require "cgi"
# JSON Feed file, folder of MP3s, and auth token
json_path = "/Users/manton/Dropbox/Documents/Timetable/Backup/timetable_posts.json"
episodes_path = "/Users/manton/Dropbox/Documents/Timetable/Episodes"
token = "..."
info = JSON.parse(
episodes = info["items"]
for e in episodes
# get title, content, and date from JSON
title = e["title"]
s = e["content_html"]
d = e["date_published"]
# parse episode number from title in format: "Episode 123: Title"
episode_number = title.split(":").first.gsub("Episode ", "")
puts "Publishing episode: #{episode_number}..."
# upload MP3 to media endpoint
response = `curl -i -F "file=@#{episodes_path}/Timetable_#{episode_number}.mp3" -H "Authorization: Bearer #{token}"`
headers = response.split("\n")
for h in headers
# published MP3 URL comes back in a Location header
name = h.split(": ").first
val = h.split(": ").last
if name == "Location"
# append audio tag to end of post text
s = s + "\n" + "<audio controls=\"controls\" src=\"#{val}\" />"
# publish the post
`curl -d "name=#{CGI.escape(title)}" -d "content=#{CGI.escape(s)}" -d "published=#{d}" -H "Authorization: Bearer #{token}"`
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment