Created
July 30, 2009 16:57
-
-
Save mcroydon/158777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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