Skip to content

Instantly share code, notes, and snippets.

@pdxmph
Last active May 15, 2020 18:56
Show Gist options
  • Select an option

  • Save pdxmph/f0ca65c62d9f67fca05da1b7a9989f20 to your computer and use it in GitHub Desktop.

Select an option

Save pdxmph/f0ca65c62d9f67fca05da1b7a9989f20 to your computer and use it in GitHub Desktop.
Save current KCRW Eclectic 24 track to a Things list
#!/usr/bin/env ruby
require 'json'
require 'date'
require 'net/http'
require 'rb-scpt'
include Appscript
# Set up things
list = "To read, etc."
things = app("Things3")
project = things.projects[list]
todos = things.to_dos
# KCRW keeps its playlist in dated files
date_path = Date.today.strftime('%Y/%m/%d')
url = "https://tracklist-api.kcrw.com/Music/date/#{date_path}"
uri = URI(url)
response = Net::HTTP.get(uri)
pl = JSON.parse(response)
# First entry in the list is the current track
current_track = pl[0]
artist = current_track['artist']
title = current_track['title']
unless current_track['itunes_url'].nil?
track_url = current_track['itunes_url']
else
track_url = current_track['affiliateLinkiTunes']
end
unless todos[its.name.eq(title)].get.length > 0
task = things.make(:at => project.beginning, :new => :to_do, :with_properties => {
:name => "#{title} by #{artist}",
:tag_names => "music,kcrw",
:notes => "Heard on KCRW at #{Time.now}\r\r#{track_url}"
})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment