Skip to content

Instantly share code, notes, and snippets.

@emcquaid
Created July 12, 2013 21:18
Show Gist options
  • Save emcquaid/5987937 to your computer and use it in GitHub Desktop.
Save emcquaid/5987937 to your computer and use it in GitHub Desktop.
update.py for pianobar pidora
#!/usr/bin/env python
import sys, csv, subprocess, os
def process(command, new = False):
if new:
with open(os.devnull, "w") as fnull: result = subprocess.Popen($
else:
with open(os.devnull, "w") as fnull: result = subprocess.call(c$
www= "/root/public_html/pidora/"
event = sys.argv[1]
lines = sys.stdin.readlines()
fields = dict([line.strip().split("=", 1) for line in lines])
artist = fields["artist"]
title = fields["title"]
album = fields["album"]
coverArt = fields["coverArt"]
album = fields["album"]
coverArt = fields["coverArt"]
rating = str(int(fields["rating"]))
detailUrl = fields["detailUrl"]
if event == "songstart":
open(www + "curSong", "w").write(title + "|" + artist + "|" + album + "$
elif event == "songfinish":
import feedparser, urllib
feed = feedparser.parse("http://www.npr.org/rss/podcast.php?id=500005")
if not os.path.lexists(www + "lastNews"): open(www + "lastNews", "w").w$
time = int(open(www + "lastNews", "r").read())
if feed.entries[0].updated_parsed.tm_hour != time:
open(www + "ctl", "w").write("p")
open(www + "lastNews", "w").write(str(feed.entries[0].updated_p$
open(www + "curSong", "w").write(feed.entries[0].title + "|" + $
process(["mpg123", feed.entries[0].id])
open(www + "ctl", "w").write("p")
elif event == "songlove":
open(www + "ctl", "w").write("p")
elif event == "songlove":
open(www + "curSong", "w").write(title + "|" + artist + "|" + album + "$
open(www + "msg", "w").write("Loved")
elif event == "songban":
open(www + "msg", "w").write("Banned")
elif event == "songshelf":
open(www + "msg", "w").write("Tired")
elif event == "usergetstations": # Code thanks t$
stationCount = int(fields["stationCount"])
stations = ""
for i in range(0, stationCount):
stations += "%s="%i + fields["station%s"%i] + "|"
stations = stations[0:len(stations) - 1]
open(www + "stationList", "w").write(stations)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment