def process_response(self, request, response):
     if request.is_ajax():
         pass
     else:
         http_req = Requests(path=request.build_absolute_uri(),
                             req_time=timezone.now(),
                             method=request.method,
                             status=response.status_code)
         http_req.save()
     return response
Example #2
0
def requests(receiver=None):
    if request.method == "POST":
        receiver = int(receiver)
        req = Requests(session["user"], receiver)
        db.session.add(req)
        db.session.commit()
        return redirect("/page/" + str(receiver))
    reqs = Requests.query.filter_by(user_2=session["user"]).all()
    senders = []
    for i in reqs:
        one = Users.query.get(i.user_1)
        senders.append(one)
    return render_template("requests.html", reqlist=senders)
Example #3
0
def request_done():
    goal = request.args.get('goal')
    time = request.args.get('time')
    clientName = request.args.get("clientName")
    clientPhone = request.args.get("clientPhone")

    with app.app_context():
        db.create_all()
        new_request = Requests(goal=goal,
                               time=time,
                               clientName=clientName,
                               clientPhone=clientPhone)
        db.session.add(new_request)
        db.session.commit()

    return render_template("request_done.html",
                           goal=study_goals['goals'][goal],
                           time=time,
                           clientName=clientName,
                           clientPhone=clientPhone)
Example #4
0
def get_requests():
    if request.method == "POST":
        requests = Requests()
        requests.id = request.json.get("id")
        requests.id_commune = request.json.get("id_commune")
        requests.request_status = request.json.get("request_status")
        requests.full_name = request.json.get("full_name")
        requests.last_name = request.json.get("last_name")
        requests.contact_phone = request.json.get("contact_phone")
        requests.address = request.json.get("address")
        requests.date = request.json.get("date")
        requests.hour = request.json.get("hour")

        db.session.add(requests)
        db.session.commit()
        return jsonify(requests.serialize_all_fields()), 200

    if request.method == "GET":
        requests = Requests.query.all()
        requests = list(map(lambda request: request.serialize_strict(), requests))
        return jsonify(requests), 200
Example #5
0
def fit():
    """ Form submit of meds
    :return:
    """
    form = MedForm(request.form)
    if request.method == 'POST' and form.validate():

        zipcode = form.zipcode.data
        # Check the zipcode

        plan = form.plan.data
        medication = form.medication.data

        ip = str(request.environ.get('HTTP_X_REAL_IP', request.remote_addr))
        rq = Requests(**dict(user=current_user.id,
                             ip=ip,
                             zipcode=zipcode,
                             plan=plan,
                             drug=medication))
        rq.save()

        # Process either medicare or medicaid
        plan_type = form.plan_type.data
        try:
            if plan_type == 'medicare':
                table = get_medicare_plan(medication, plan, zipcode)
            else:
                table = get_medicaid_plan(medication, plan, zipcode, plan_type)

        except tools.BadPlanName as e:
            form.errors['plan_name'] = str(e)
            context = {'form': form}
            html = 'fit.html'

        except tools.BadLocation as e:
            form.errors['zipcode'] = str(e)
            context = {'form': form}
            html = 'fit.html'
        else:
            # You have to order the data in a list or it won't show right
            data = []
            for item in table['data']:
                row = [item[h] for h in table['heading']]
                data.append(row)

            context = {
                'data': data,
                'head': table['heading'],
                'drug': medication,
                'pa': table['pa'],
                'zipcode': zipcode,
                'plan': plan,
                'plan_type': form.plan_type.data,
            }
            html = 'table.html'

    # If its a GET see if parameters were passed
    else:
        if request.method == 'GET':
            form.zipcode.data = request.args.get('zipcode', "")
            form.plan.data = request.args.get('plan', "")
            form.medication.data = request.args.get('drug', "")
            form.plan_type.data = request.args.get('plan_type', "medicare")

        # a POST with errors
        elif form.errors:
            if 'plan_type' in form.errors:
                form.errors[
                    'plan_type'] = "Please pick a Medicare, Medicaid, or Private plan"

        context = {'form': form}
        html = 'fit.html'

    content = render_template(html, **context)
    return content
 def process_request(self, request):
     if request.is_ajax():
         return None
     save_request = Requests(request=request,
                             path=request.build_absolute_uri())
     return save_request.save()
Example #7
0
# For each station
for station in Stations.query.all():

    # Request page with all schedule data for that station
    url = 'http://dv.njtransit.com/mobile/tid-mobile.aspx?sid=' + station.abbr
    request_time = time.time()
    trains_page = requests.get(url)
    request_time = time.time() - request_time
    trains_tree = html.document_fromstring(trains_page.text)

    # Scrape stations
    for elem in trains_tree.xpath('//table'):
        if len(elem.getchildren()) == 1 and len(
                elem.getchildren()[0].getchildren()) == 6:
            values = [
                re.sub('[^a-zA-Z0-9- :_*.]', '',
                       x.text_content().strip())
                for x in (elem.getchildren()[0].getchildren())
            ]
            schedule = Schedule(values[0], values[1], values[2], values[3],
                                values[4], values[5])
            station.schedules.append(schedule)
            print values

    db.session.add(Requests(url, request_time, version))

db.session.commit()

print "Success."