summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErnesto Rico-Schmidt <ernesto.rico-schmidt@evolaris.net>2016-09-16 16:29:07 (GMT)
committerErnesto Rico-Schmidt <ernesto.rico-schmidt@evolaris.net>2016-09-16 16:29:07 (GMT)
commitbee4dba4ed6c8519a9a87027d20d3c3f284ec7fa (patch)
treebcd4bbc962d45ec2098a3667614323d22d5088f0
parentf0b1c87dfe1c63a7e17dbc6c0df8c2a8c9dab060 (diff)
added support for multi-shows in JSON.
-rw-r--r--program/utils.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/program/utils.py b/program/utils.py
index 40bcb2a..3befeaf 100644
--- a/program/utils.py
+++ b/program/utils.py
@@ -2,6 +2,7 @@ from django.conf import settings
import json
import urllib
+import bisect
from os.path import join
from datetime import datetime, date, timedelta
@@ -15,17 +16,27 @@ def get_automation_id_choices():
try:
shows_json = urllib.urlopen(base_url).read()
shows_list = json.loads(shows_json)['shows']
+ multi_shows_list = json.loads(shows_json)['multi-shows']
except IOError:
try:
with open(cached_shows) as cache:
shows_list = json.loads(cache.read())['shows']
+ multi_shows_list = json.loads(cache.read())['multi-shows']
except IOError:
shows_list = []
+ multi_shows_list = []
else:
with open(cached_shows, 'w') as cache:
cache.write(shows_json)
- shows = [(s['id'], '%d | %s' % (s['id'], s['title'])) for s in shows_list]
+ shows = [(s['id'], '%d | %s' % (s['id'], s['title']), s['title']) for s in shows_list if not s.get('multi')]
+
+ [bisect.insort(shows, (s['id'], '%05d | %s' % (s['id'], s['title']), s['title'])) for s in multi_shows_list]
+
+ shows.sort(key=lambda show: show[2].lower())
+
+ shows = [(s[0], s[1]) for s in shows]
+
return shows