Example #1
0
def index():
    lunch_form = LunchBlocks()
    version_form = VersionDescription()
    announcement_form = Announcements()

    form_btn = request.form.get('btn')

    if form_btn == LUNCH_BLOCKS_UPDATE_TITLE and lunch_form.validate_on_submit():
        week_day_name = lunch_form.week_and_day.data
        try:
            english_week_day_name = DAY_CHOICES_D[week_day_name]
            db.update_distinctions(lunch_form.blocks.data,
                                   week_day_name,
                                   english_week_day_name)
            flash('lunch blocks were updated if changes were made')
        except KeyError:
            flash('bad day name')
    elif form_btn == ADD_VERSION_TITLE and version_form.validate_on_submit():
        db.insert_version_description(version_form.version_number.data,
                                      version_form.whats_new.data,
                                      version_form.ios_supported.data,
                                      version_form.available_since.data.strftime(VERSION_RELEASED_FORMAT))
        flash('version added/modified to/in About')
    elif form_btn == ANNOUNCEMENT_TITLE and announcement_form.validate_on_submit():
        eastern = timezone('US/Eastern')
        expires_dt_et = eastern.localize(announcement_form.expires.data)
        db.add_announcement(announcement_form.announcement.data,
                            expires_dt_et,
                            announcement_form.url.data)
        sr.flushall()
        flash('Announcement added! It will appear immediately.')

    return render_template('admin.html',
                           title='Admin',
                           logged_in=loggedin(),
                           lunch_title=LUNCH_BLOCKS_UPDATE_TITLE,
                           version_title=ADD_VERSION_TITLE,
                           announcement_title=ANNOUNCEMENT_TITLE,
                           announcements=db.get_announcements(),
                           lunch_form=lunch_form,
                           version_form=version_form,
                           announcement_form=announcement_form,
                           forms=db.get_forms(),
                           js=[url_for('static', filename='js/loadJSON.js'),
                               url_for('static', filename='js/admin.js')])
Example #2
0
File: api.py Project: mbsdev/helper
def today(division):
    """generate Today feed
    """

    if not DEBUG:
        if sr.exists(request.url):
            return justmime(sr.get(request.url))

    eastern = pytz.timezone('US/Eastern')
    date = datetime.datetime.now(eastern)
    is_weekend = date.weekday() >= 5

    items = get_remote_feeds(division, date, is_weekend)
    pool = Pool(len(items))
    responses = map(perform_query, items)
    # we won't modify the pool further
    pool.close()
    # wait for the threads to finish...
    pool.join()

    feed = filter_and_chain(responses)

    for a in db.get_announcements():
        to_add = {
            'class': 'standard',
            'img': 'announcement.png',
            'text': a['text']
        }

        if 'url' in a.keys() and len(a['url']) > 5:
            to_add['url'] = a['url']

        feed.insert(0, to_add)

    feed.insert(0, {
        'class': 'standard',
        'img': 'pin.png',
        'text': 'It\'s %s%s.' % (date.strftime('%A, %B %-d'), day_suffix(date.day)) 
    })

    if request.args.get('tz') and (request.args.get('tz') != 'America/New_York'):
        feed.insert(1, {
            'class': 'standard',
            'img': 'timezone.png',
            'text': 'Your\'re not in the US/Eastern timezone. Tap to read how MBS Now handles this.',
            'more': 'All dates in the app are in US/Eastern regardless of your current timezone. One stipulation is that if you add an event from MBS Now to your iOS calendar, the date in the calendar will reflect your current (non-US/Eastern) timezone. Happy travels!'
        })


    lunch_query_name = date.strftime('%A')
    lunch_today = db.get_lunch_menu(lunch_query_name)
    if lunch_today is not None:
        feed.insert(3, {
            'class': 'standard',
            'img': 'lunch.png',
            'text': 'Lunch: %s.' % (lunch_today['menu'])
        })

    athletics_message = {
        'class': 'standard',
        'img': 'calendar.png',
        'url': 'http://www.nwjerseyac.com/g5-bin/client.cgi?G5genie=235&G5button=13&school_id=22',
        'text': 'Tap for the athletics calendar.'
    }

    feed.append(athletics_message)

    to_return = json.dumps({
        'ok': 1,
        'query': request.url,
        'navtitle': u'Today \u00b7 %s' % date.strftime('%A'),
        'result': feed
    })

    sr.set(request.url, to_return)
    # expire cache in 60 * 15 = 15 minutes
    sr.expire(request.url, 60 * 15)
    
    return justmime(to_return)
Example #3
0
# -*- coding: utf-8 -*-
"""
    Removes expired announcements from db.
    Run at least every 2-hours with cron.
"""
import db
import datetime

if __name__ == '__main__':
    for a in db.get_announcements():
        if datetime.datetime.now() > a['expiration']:
            db.delete_announcement(a['_id'])