def img_schedule(item): process_img_sched = lambda j: json.load(j)[item.division] tomorrow_img = urllib2.urlopen(url_writer.img_schedule(item.date + timedelta(days=1))) res = ({ 'today_sched': process_img_sched(item.resp), 'tomorrow_sched': process_img_sched(tomorrow_img), 'url': DAY_SCHED_URL, 'class': 'schedule' }) return res
def get_remote_feeds(division, date, is_weekend): version = request.args.get('v') if division.lower() not in {'ms', 'us'} : raise UsageError('bad-division') elif not version: raise UsageError('bad-version') items = [ TodayItem(ITUNES_VERSION, date, resp_process.version, version=version), TodayItem(url_writer.text_schedule(date, division), date, resp_process.text_schedule), TodayItem(OPEN_WEATHER_MAP_URL, date, resp_process.weather, version=version), TodayItem(RSS_EVENTS_URL, date, resp_process.events, filter_events=(request.args.get('month_events') != '1')), TodayItem(RSS_NEWS_URL, date, resp_process.news, filter_news=(request.args.get('month_news') != '1')) ] if not is_weekend: # only fetch the img schedule if it's a weekday items.insert(1, TodayItem(url_writer.img_schedule(date), date, resp_process.img_schedule, division=division)) return items
# -*- coding: utf-8 -*- """ Updates database if current day (ET) is an A or B week. Run at least daily with cron. """ import db import datetime import url_writer import urllib2 import pytz import json if __name__ == '__main__': eastern = pytz.timezone('US/Eastern') date = datetime.datetime.now(eastern) img_schedule_api = url_writer.img_schedule(date) api_resp = urllib2.urlopen(img_schedule_api) img = json.load(api_resp)['US'] if 'A_' in img: db.set_ab_week('A', date) elif 'B_' in img: db.set_ab_week('B', date) else: db.clear_ab_weeks()