def plans(): """ Plan name API find similar to spelling http://localhost:5000/plans?zipcode=36117&qry=Hum :return: json list of plan names """ results = [] if 'qry' in request.args: look_for = request.args['qry'] if look_for[0] == '*': look_for = '' zipcode = request.args['zipcode'] try: plan = request.args['plan'] except KeyError: return None # If this is a medicaid or private plan where = tools.get_location(zipcode) if where: if plan in ('medicaid', 'private'): state = where.STATE results = PlanNames.by_state(state, look_for, plan == 'medicaid') results = [r.plan_name for r in results] if state == 'OH': results.append('OH State Medicaid') elif plan == 'medicare': county_code = where.GEO.COUNTY_CODE ma_region = where.GEO.MA_REGION_CODE pdp_region = where.GEO.PDP_REGION_CODE results = Plans.find_in_county(county_code, ma_region, pdp_region, look_for) return jsonify(sorted(results))
def add_plan(): errors = [] if request.is_json: data = request.get_json() print(data) plan = Plans(date=data.get('date'), meal_id=data.get('meal')) db.session.add(plan) db.session.commit() return str(plan.id), 200
def search_submit(start_sta, end_sta, preference): #start_sta = request.query.start_sta #end_sta = request.query.end_sta results, start_trains, end_trains = save_direct_plans(start_sta, end_sta) if not results: results = save_tranfer_one_plans(start_trains, end_trains) if preference == "travel_time": result = sorted(results, key=attrgetter('travel_time', 'distance')) else: result = sorted(results, key=attrgetter('distance', 'travel_time')) plans = Plans(start_sta, end_sta,edges=result[:5]) if 'callback' in request.query: callback = request.query.callback response.content_type = 'application/javascript' return callback + '(' + plans.to_json() + ');' else: response.content_type = 'application/json' return json.dumps(plans.to_dict(), indent=4)
def get_plan(plan_name, zipcode): """ Get the formulary_id for a plan :param plan_name: Full or partial name of a plan :param zipcode: zipcode for the plan :return: a formulary_id for that plan for that zipcode """ zipcode = get_location(zipcode) plans = Plans.find_by_plan_name(plan_name, geo=zipcode.GEO.id) # There should only be one if len(plans) == 1: return plans[0] else: raise BadPlanName(f"Plan {plan_name} in {zipcode} not found")
"MA", "02138", "USA", "*****@*****.**", "9518162589", "it's a secret", "VENDOR", "cus_4fdAW5ftNQow1a")) db.session.add(Users( "javi", "fakes address", "Ranchoi", "CA", "91739", "USA", "*****@*****.**", "9518162555", "password", "CUSTOMER", "cus_4fdAW5ftNQow1a")) ''' db.session.add( Plans("plan_DSJ2J4GWgA6gV7", 1500, "Standard monthly vendor subscription")) db.session.add( Plans("plan_DSJ5PYWe9JZnuh", 3200, "Gold monthly vendor subscription")) #commit db.session.commit()
result = sorted(results, key=attrgetter('travel_time', 'distance')) else: result = sorted(results, key=attrgetter('distance', 'travel_time')) plans = Plans(start_sta, end_sta,edges=result[:5]) if 'callback' in request.query: callback = request.query.callback response.content_type = 'application/javascript' return callback + '(' + plans.to_json() + ');' else: response.content_type = 'application/json' return json.dumps(plans.to_dict(), indent=4) if __name__ == '__main__': import time import sys start_sta = raw_input("start station:") end_sta = raw_input("end station:") start_time = time.time() results,start_trains,end_trains = save_direct_plans(start_sta, end_sta) if not results: results = save_tranfer_one_plans( start_trains, end_trains ) if not results: results = save_tranfer_all_plans( start_trains, end_trains ) result = sorted(results, key=attrgetter('travel_time','distance')) plans = Plans(start_sta, end_sta,edges=result[:1]) elapsed = time.time() - start_time print elapsed print plans.to_json()
def add_meal(): message = [] results = {} if request.method == "POST": try: title = request.form['title'] ingredients = request.form['ingredients'] instructions = request.form['instructions'] image = request.form['image'] url = request.form['url'] date = request.form['plan_date'] if date: datum = datetime.strptime(date, "%Y-%M-%d").strftime("%Y-%M-%d") else: datum = '' results = { 'title': title, 'ingredients': ingredients, 'instructions': instructions, 'image': image, 'url': url, 'date': datum } try: meal = Meals(title=title, ingredients=ingredients, instructions=instructions, image=image, url=url, date_added=datetime.utcnow()) db.session.add(meal) db.session.flush() if date: plan = Plans(date=date, meal_id=meal.id) db.session.add(plan) db.session.commit() message.append({ 'title': "Successfully added {}".format(title), 'state': "success" }) except Exception as err: message.append({ 'title': 'Could not update database.', 'message': '{}'.format(err), 'state': 'error' }) except Exception as err: message.append({ 'title': "Error with form.", 'message': "{}".format(err), 'state': 'error' }) return render_template('add-meal.html', page_title="Mealer | Add Meal", message=message, values=results)