Example #1
0
def signup():
    version = randint(0, 1000000)
    login = LoginForm()
    address = AddressForm()
    if address.validate_on_submit():
        x, y = get_lambert(address.address.data)
        size = int(address.window.data)
        tif = GeoTIFF.get_tif_from_point(x, y).crop_location(x, y, size, size)
        if address.projection.data == "2D": tif.png()
        else:
            xaxis = go.XAxis(range=[0.2, 1],
                             showgrid=False,
                             zeroline=False,
                             visible=False)
            yaxis = go.YAxis(range=[0.2, 1],
                             showgrid=False,
                             zeroline=False,
                             visible=False)
            layout = go.Layout(xaxis=xaxis,
                               yaxis=yaxis,
                               paper_bgcolor='rgba(0,0,0,0)',
                               scene_aspectmode='manual',
                               scene_aspectratio=dict(x=1.5, y=1.5, z=0.5),
                               margin=dict(l=0, r=0, b=0, t=0))
            fig = go.Figure(data=[go.Surface(z=tif.arr)], layout=layout)
            fig.write_image(directory + "/app/static/plot.png")

    return render_template("geoloc.html",
                           version=version,
                           form={
                               "login": login,
                               "address": address
                           })
Example #2
0
def edit_address():
    form = AddressForm(current_user.username)
    if form.validate_on_submit():
        language = guess_language(form.address.data)
        if language == 'UNKNOWN' or len(language) > 5:
            language = ''
        address = Address(body=form.address.data, author=current_user)
        db.session.add(address)
        db.session.commit()
        flash(_('Your changes have been saved.'))
        return redirect(url_for('edit_address'))
    page = request.args.get('page', 1, type=int)
    addresses = current_user.addresses.order_by(
        Address.timestamp.desc()).paginate(page, 25, False)
    next_url = url_for('index', page=addresses.next_num) \
        if addresses.has_next else None
    prev_url = url_for('index', page=addresses.prev_num) \
        if addresses.has_prev else None

    return render_template('edit_address.html',
                           title=_('Edit Address'),
                           form=form,
                           addresses=addresses.items,
                           next_url=next_url,
                           prev_url=prev_url)
Example #3
0
def edit_address(address_id):
    address = Address.query.get(address_id)
    if not address or address.user_id != current_user.id:
        return redirect(url_for('address_book'))

    form = AddressForm()
    if form.validate_on_submit():
        address.first_name = form.first_name.data.title()
        address.last_name = form.last_name.data.title()
        address.address = form.address.data.title()
        address.city = form.city.data.title()
        address.state = form.state.data
        address.zip_code = form.zip_code.data

        db.session.commit()
        return redirect(url_for('address_book'))

    form.first_name.data = address.first_name
    form.last_name.data = address.last_name
    form.address.data = address.address
    form.city.data = address.city
    form.state.data = address.state
    form.zip_code.data = address.zip_code

    return render_template(
        'address_form.html',
        form=form,
        form_title="Edit Address",
    )
Example #4
0
def textaddress():
    #adding form that accepts address
    form = AddressForm()

    # text to address and value form
    if form.validate_on_submit():

        address = form.address.data

        # bing address grabber
        bing_locator = geocoders.Bing(bing_key)
        address = bing_locator.geocode(address).raw

        # Zillow call (could be replaced with Zillow function)
        zillow_api = zillow.ValuationApi()
        house = address['address']['addressLine']
        postal_code = address['address']['postalCode']

        house_data = zillow_api.GetSearchResults(zillow_key, house,
                                                 postal_code)
        price = house_data.zestimate.amount

        # set address back to street address and zip code
        address = address['name']

        ### START GOOGLE STREET VIEW IMAGE HANDLING ###

        # Set image_url to Google Street View of address

        image_url = f'https://maps.googleapis.com/maps/api/streetview?size=600x600&location={address}&key={google_key}'

        # Image write out to uploads folder
        image = requests.get(image_url)

        basepath = os.path.abspath('app/')
        filelist = re.findall(r'\w+', address)
        filename = ''.join(filelist)
        final_path = f'{basepath}/uploads/{filename}.jpg'
        open(f'{final_path}', 'wb').write(image.content)

        # render template with passed variables when form validates
        return render_template('text_form.html',
                               title='Output',
                               price=price,
                               address=address,
                               file_path=f'{filename}.jpg',
                               photo=open(f'{final_path}', 'rb'))

    #keep same page with form if form does not validate
    return render_template('textaddress.html',
                           title='Submit Address',
                           form=form)
Example #5
0
def textaddress():
    form = AddressForm()

    if form.validate_on_submit():
        # flash('Login requested for user {}'.format(form.address.data))

        address = form.address.data

        bing_key = ''
        bing_locator = geocoders.Bing(bing_key)
        address = bing_locator.geocode(address).raw

        zillow_key = ''
        zillow_api = zillow.ValuationApi()
        house = address['address']['addressLine']
        postal_code = address['address']['postalCode']

        house_data = zillow_api.GetSearchResults(zillow_key, house,
                                                 postal_code)
        price = house_data.zestimate.amount
        address = address['name']

        google_key = ''

        ### START GOOGLE STREET VIEW IMAGE HANDLING ###

        # Set image_url to Google Street View of address
        # I don't know how this will need to be saved / returned for use in Flask
        image_url = f'https://maps.googleapis.com/maps/api/streetview?size=600x600&location={address}&key={google_key}'

        # Put image handling code for Flask here
        image = requests.get(image_url)

        basepath = os.path.abspath('app/')
        filelist = re.findall(r'\w+', address)
        filename = ''.join(filelist)
        final_path = f'{basepath}/uploads/{filename}.jpg'
        open(f'{final_path}', 'wb').write(image.content)

        return render_template('text_form.html',
                               title='Output',
                               price=price,
                               file_path=f'{filename}.jpg',
                               photo=open(f'{final_path}', 'rb'))

        # return redirect('/textaddress')

    return render_template('textaddress.html',
                           title='Submit Address',
                           form=form)
Example #6
0
def geocode():
    form = AddressForm()
    if form.validate_on_submit():
        geocode_string = {'addressLine': form.address.data}
        geocode_response = requests.request('GET',
                                            geocode_url,
                                            headers=headers,
                                            params=geocode_string)

        flash('Geocode Requested For: {} and geocode string {}'.format(
            form.address.data, geocode_string))
        flash(geocode_response.text)

        return redirect(url_for('geocode'))
    return render_template('geocode.html', form=form)
Example #7
0
def create():
    """ Address New """
    form = AddressForm()
    if form.validate_on_submit():
        form_data = {
            'name': form.name.data,
            'address': form.address.data,
            'zip': form.zip.data,
            'city': form.city.data,
            'state': form.state.data
        }
        validator = ZipService()
        validator.validate_address(form_data)
        flash('{} Created Successfully'.format(form.name.data))
        return redirect('/')
    return render_template('create.html', form=form)
Example #8
0
def add_address():
    form = AddressForm()
    if form.validate_on_submit():
        address = Address(first_name=form.first_name.data.title(),
                          last_name=form.last_name.data.title(),
                          address=form.address.data.title(),
                          city=form.city.data.title(),
                          state=form.state.data,
                          zip_code=form.zip_code.data,
                          user_id=current_user.id)
        db.session.add(address)
        db.session.commit()
        return redirect(url_for('address_book'))

    return render_template('address_form.html',
                           form=form,
                           form_title='Add A New Address')
Example #9
0
def hazard():
    form = AddressForm()
    if form.validate_on_submit():
        hazard_request = dict(
            reportList=
            'floodRatingFEMA,floodRiskScore,slosh,stormSurge,propertyInformation,wildfireRiskScore',
            addressLine=form.address.data)
        resp = requests.request('GET',
                                reports_url,
                                headers=headers,
                                params=hazard_request)

        flash('Hazard Requested For: {}'.format(form.address.data))
        flash(resp.text)

        return redirect(url_for('hazard'))

    return render_template('hazard.html', form=form)
Example #10
0
def getAddressForm():
    form = AddressForm()
    print("form.data", form.data)
    form['csrf_token'].data = request.cookies['csrf_token']
    print(",,,,,,,,,,,,,,,,,,,,,,,,,,,", form['csrf_token'].data)

    if form.validate_on_submit():
        streetData = form.data['street_address']
        cityData = form.data['city']
        stateData = form.data['state']
        zipData = form.data['zip_code']
        address = Address(userId=current_user.id,
                          street_address=streetData,
                          city=cityData,
                          state=stateData,
                          zip_code=zipData)
        db.session.add(address)
        db.session.commit()
        return "hello"
    print("did not work")
    return "error: address incomplete"