Skip to content

Instantly share code, notes, and snippets.

@Elwell
Created June 28, 2012 08:39
Show Gist options
  • Save Elwell/3009947 to your computer and use it in GitHub Desktop.
Save Elwell/3009947 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# script to parse out the metadata from soma fm and send to mqtt
xmlurl = 'http://api.somafm.com/channels.xml'
from lxml import etree
tree = etree.parse(xmlurl)
interesting = ('title','description','image','twitter','listeners','dj')
for chan in tree.getiterator('channel'):
for thing in interesting:
for key in chan.iterchildren(tag=thing):
print "somafm/%s/%s %s" % (chan.attrib['id'], key.tag, key.text)
@bigkevmcd
Copy link

!/usr/bin/env python

script to parse out the metadata from soma fm and send to mqtt

xmlurl = 'http://api.somafm.com/channels.xml'

from pyquery import PyQuery

query = PyQuery(url=xmlurl, parser='xml')

for channel in query('channel'):
channel = PyQuery(channel)
print channel.find('title').text()
print channel.find('description').text()
print channel.find('image').text()
print channel.find('twitter').text()
print channel.find('listeners').text()
print channel.find('dj').text()

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