Skip to content

Instantly share code, notes, and snippets.

@mcroydon
Created July 30, 2009 16:57
Show Gist options
  • Save mcroydon/158777 to your computer and use it in GitHub Desktop.
Save mcroydon/158777 to your computer and use it in GitHub Desktop.
import appuifw
import e32
import simplejson as json
import urllib
def exit_key_handler():
app_lock.signal()
info = []
main_listbox = None
def noop():
pass
def handle_station():
station = info[main_listbox.current()].split("-")[1].strip()
data = json.loads(urllib.urlopen('http://api.yes.com/1/recent?name=%s' % station).read())
station_info = []
for result in data["songs"]:
station_info.append("%s by %s" % (result["title"], result["by"]))
station_listbox = appuifw.Listbox(station_info, noop)
appuifw.app.body = station_listbox
raw_info = []
def _cmp(x,y):
return cmp(x[1], y[1])
data = json.loads(urllib.urlopen('http://api.yes.com/1/stations?loc=66044&max=100').read())
for result in data["stations"]:
raw_info.append((result["name"], float(result["desc"].split("-")[0].strip())))
raw_info.sort(_cmp)
for result in raw_info:
info.append("%s - %s" % (result[1], result[0]))
main_listbox = appuifw.Listbox(info,handle_station)
app_lock = e32.Ao_lock()
appuifw.app.body = main_listbox
appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment