Skip to content

Instantly share code, notes, and snippets.

/x.py

Created May 3, 2014 20:17
Show Gist options
  • Save anonymous/11505106 to your computer and use it in GitHub Desktop.
Save anonymous/11505106 to your computer and use it in GitHub Desktop.
extract channel info from http://sky.fm and make a json blob
#!/usr/bin/env python
import json
from pprint import pprint
import urllib
serviceurl = 'http://www.sky.fm'
data = urllib.urlopen(serviceurl)
page = data.readlines()
findme = "NS('AudioAddict.API.Config').channels"
json_list = []
for line in page:
if findme in line:
# We don't want the preamble, only the json blob, so find where in the
# line the blob begins '[', then extract and strip whitespace. The
# result will have a semi-colon at the end, so remove that, then load
# the blob as a json (list) object.
pos = line.find('[')
json_blob = line[pos:].strip()
json_blob = json_blob[:-1]
json_list = json.loads(json_blob)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment