Skip to content

Instantly share code, notes, and snippets.

Last active Sep 25, 2017
What would you like to do?
Polls the Jack FM website every 60 seconds to see what song they're playing, and records it to an SQLite database. More details at
require 'open-uri'
require 'sqlite3'
require 'nokogiri'
# Load DB, create schema if absent
db = 'log.db'
db.execute "CREATE TABLE IF NOT EXISTS plays (time INTEGER, artist TEXT, song TEXT);"
# Utility functions
def wait(seconds = 60)
tx = + seconds
sleep(tx - while(tx >
# Logger
last = [nil, nil]
printf "%-23s | %-20s | %s\n", 'Time', 'Artist', 'Song'
while true do
html = Nokogiri::HTML(open(""))
artist, song = html.at_css('.now-playing__artist strong').text, html.at_css('.now-playing__song').text
if last != [artist, song]
# song has changed since we last checked
printf "%-23s | %-20s | %s\n",, artist, song
db.execute "INSERT INTO plays (time, artist, song) VALUES (?, ?, ?)",, artist, song
last = [artist, song]
wait # for a minute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment