Skip to content

Instantly share code, notes, and snippets.

@capoferro
Created February 3, 2011 05:18
Show Gist options
  • Select an option

  • Save capoferro/809081 to your computer and use it in GitHub Desktop.

Select an option

Save capoferro/809081 to your computer and use it in GitHub Desktop.
Automatically log into pandora with pianobar.
#! /usr/lib/ruby
require 'open3'
Open3.popen2('pianobar', 'r+') do |stdin, stdout|
out = ''
sleep_now = false
loop do
o, i, _ = IO.select([stdout], [stdin], nil, 10000000)
unless o.first.nil?
out += o.first.readpartial(8000)
end
case out
when /\n$/
print out
out.clear
when /Username:\ /
print out
out.clear
i.first.write "youremail@example.com"
when /Password:\ /
print out
out.clear
i.first.write "supersecret\n"
when /Select station:\ /
print out
out.clear
input_complete = true
i.first.write "#{gets}\n"
sleep_now = true
end
# Otherwise the script pegs CPU @ 100%
if sleep_now
print out
out.clear
sleep(10)
end
end
end
@seca

seca commented Feb 3, 2011

Copy link
Copy Markdown

This isn't working for me. It seems like it might go to sleep even though sleep_now=false. Any chance you can post the old script for comparison. I accidentally overwrote it after moving it.

Thanks for messaging me. I find myself wanting pause for when I need to step away for a moment. I'll let you know if I come up with anything.

@capoferro

Copy link
Copy Markdown
Author

sleep_now should be nil until you issue your station's number.

https://gist.github.com/809428

Perhaps it has issues on 1.9.1? Could try upgrading to 1.9.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment