示例#1
0
def get_gush(gush_id):
    """
    get gush_id metadata
    """
    gush = helpers._get_gushim(query={"gush_id": gush_id})
    if gush is None or len(gush) == 0:
        abort(404)
    return helpers._create_response_json(gush[0])
示例#2
0
def get_gush(gush_id):
    """
    get gush_id metadata
    """
    gush = helpers._get_gushim(query={"gush_id": gush_id})
    if gush is None or len(gush) == 0:
        abort(404)
    return helpers._create_response_json(gush[0])
示例#3
0
def find_plan(plan_name):
    """
    Find plans that contain the search query and return a json array of their plan and gush ids
    """
    return helpers._create_response_json(
        helpers._get_plans(count=3,
                           query={'number': {
                               '$regex': '.*%s.*' % plan_name
                           }}))
示例#4
0
def get_plans(gushim):
    """
    Get JSON plan data for one or more gush IDs.
    The URL format for multiple gushim is something like /gush/12340,12350,12360/plans.json
    """
    gushim = gushim.split(',')
    if len(gushim) > 1:
        gushim_query = {'gushim': {'$in': gushim}, 'year': {'$gt': datetime.datetime.now().year - 10}}
    else:
        gushim_query = {'gushim': gushim[0]}

    return helpers._create_response_json(helpers._get_plans(query=gushim_query))
示例#5
0
def get_plans(gushim):
    """
    Get JSON plan data for one or more gush IDs.
    The URL format for multiple gushim is something like /gush/12340,12350,12360/plans.json
    """
    gushim = gushim.split(',')
    if len(gushim) > 1:
        gushim_query = {
            'gushim': {
                '$in': gushim
            },
            'year': {
                '$gt': datetime.datetime.now().year - 10
            }
        }
    else:
        gushim_query = {'gushim': gushim[0]}

    return helpers._create_response_json(
        helpers._get_plans(query=gushim_query))
示例#6
0
def get_recent_plans():
    """
    Get the 10 most recent plans to show on the site's home page
    """
    return helpers._create_response_json(helpers._get_plans(count=10))
示例#7
0
def wakeup():
    """
    wake up Heroku dyno from idle. perhaps can if >1 dynos
    used as endpoint for a "wakeup" request when the client inits
    """
    return helpers._create_response_json({'morning': 'good'})
示例#8
0
def find_plan(plan_name):
    """
    Find plans that contain the search query and return a json array of their plan and gush ids
    """
    return helpers._create_response_json(helpers._get_plans(count=3, query={'number': {'$regex': '.*%s.*' % plan_name}}))
示例#9
0
        # Merge stats into gushim dict
        for g in stats['result']:
            try:
                gush_id = g['_id']['gush_id']
                status = g['_id']['status']
                g_flat[gush_id]['plan_stats'][status] = g['count']
            except KeyError, e:
                # Gush has plans but is missing from list of gushim?
                app.logger.warn("Gush #%d has plans but is not listed in the Gushim list", gush_id)
                app.log_exception(e)

        # De-flatten our dict
        gushim = g_flat.values()

    return helpers._create_response_json(gushim)


@app.route('/gush/<gush_id>.json')
@cached(app, timeout=3600)
def get_gush(gush_id):
    """
    get gush_id metadata
    """
    gush = helpers._get_gushim(query={"gush_id": gush_id})
    if gush is None or len(gush) == 0:
        abort(404)
    return helpers._create_response_json(gush[0])


@app.route('/gush/<gushim>/plans.json')
示例#10
0
def wakeup():
    """
    wake up Heroku dyno from idle. perhaps can if >1 dynos
    used as endpoint for a "wakeup" request when the client inits
    """
    return helpers._create_response_json({'morning': 'good'})
示例#11
0
def get_recent_plans():
    """
    Get the 10 most recent plans to show on the site's home page
    """
    return helpers._create_response_json(helpers._get_plans(count=10))
示例#12
0
        for g in stats['result']:
            try:
                gush_id = g['_id']['gush_id']
                status = g['_id']['status']
                g_flat[gush_id]['plan_stats'][status] = g['count']
            except KeyError, e:
                # Gush has plans but is missing from list of gushim?
                app.logger.warn(
                    "Gush #%d has plans but is not listed in the Gushim list",
                    gush_id)
                app.log_exception(e)

        # De-flatten our dict
        gushim = g_flat.values()

    return helpers._create_response_json(gushim)


@app.route('/gush/<gush_id>.json')
@cached(app, timeout=3600)
def get_gush(gush_id):
    """
    get gush_id metadata
    """
    gush = helpers._get_gushim(query={"gush_id": gush_id})
    if gush is None or len(gush) == 0:
        abort(404)
    return helpers._create_response_json(gush[0])


@app.route('/gush/<gushim>/plans.json')