Skip to content
Snippets Groups Projects
Commit 8350d681 authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

Remove get_automation_id_choices from utils

parent dd0afded
No related branches found
No related tags found
No related merge requests found
......@@ -18,52 +18,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import bisect
import json
import urllib
from datetime import datetime, date, timedelta
from os.path import join
from django.conf import settings
def get_automation_id_choices():
base_url = getattr(settings, 'AUTOMATION_BASE_URL', None)
cache_dir = getattr(settings, 'AUTOMATION_CACHE_DIR', 'cache')
cached_shows = join(cache_dir, 'shows.json')
shows = []
if base_url:
try:
shows_json = urllib.request.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']), 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
def get_cached_shows():
cache_dir = getattr(settings, 'AUTOMATION_CACHE_DIR', 'cache')
cached_shows = join(cache_dir, 'shows.json')
shows = {}
with open(cached_shows) as shows_json:
shows = json.loads(shows_json.read())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment