Ejemplo n.º 1
0
def index():
    '''This method is initially a little wonky because it contains two different forms
        within the same view. The ideal way may be just to present two different pages
        but this provides a more consistent user experience and is how it was originally
        written. It operates as follows:
            1.  checks to see if street name/address were set in the sessions dict on a
                previous run. Otherwise makes sure the variable used for this info later
                is set to None for checks.
            2.  Checks if first run (loop of view with data entered); sets up default variables
            3.  Checks if second run; gets entered street name and crawls for arrondissment choices
            4.  Checks if third (final) run; gets input arrondissment choice, scrapes assessment roll 
                and direct to success page
            5.  Success page - display .csv to download and return link; reinitialize form
    '''

    street_form = StreetForm() #enter street name
    address_form = AddressRange() #enter street address range

    if request.method == 'POST':
        if session.get('street_name') and not street_form.street_name.data:
            street_form.street_name.data = session.get('street_name')
        if session.get('start_address'):
            street_form.street_name.data = session.get('start_address')

    # clear blank field input for logic tests
    if street_form.street_name.data == '':
        street_form.street_name.data = None
    if address_form.start_address.data == '':
        address_form.start_address.data = None

    # if first run
    if not street_form.street_name.data:
        init_session()
    # elif street name has been entered but no data is in other fields
    elif street_form.street_name.data and not address_form.start_address.data:
        street_string = format_streetname(str(street_form.street_name.data))
        if session.get('street_name') != street_string:
            session['street_name'] = street_string
        print session['street_name']
        street_form.validate_on_submit()
        try:
            session['nbhood_form_fields'], session['nbhood_full_list'] = RollScraper.get_nbhoods_list(
                BrowserInstance, session['street_name'])
        except AttributeError:
            flash('Street name not found, please check and try again.')
            init_session()
        except Exception, e:
            flash(e)
            init_session()
        return render_template('forms.html', 
                        title="Montreal Assessment Roll Scraper",
                        street_form=street_form,
                        address_form=address_form,
                        neighborhood_list=session['nbhood_form_fields'])
Ejemplo n.º 2
0
     # if address_form.end_address.data.strip() == '':
     end_address = None
     # else:
     #     end_address = int(address_form.end_address.data.strip())
 except:
     flash('Invalid address entered, please enter an integer only.')
     init_session()
     return render_template('forms.html', 
                     title="Montreal Assessment Roll Scraper", 
                     street_form=street_form,
                     address_form=AddressRange(),
                     neighborhood_list=session['nbhood_form_fields'])
 # execute the query to the assessment role webui
 try:
     scraped_data = RollScraper.enter_street_address(
         BrowserInstance, session['nbhood_full_list'], selection_index,
         start_address, end_address)
 except Exception, e:
     flash(e)
     init_session()
     return render_template('forms.html', 
                     title="Montreal Assessment Roll Scraper", 
                     street_form=street_form,
                     address_form=AddressRange(),
                     neighborhood_list=session['nbhood_form_fields'])
 # construct the .csv filenames 
 csv_files = {}
 for address, data_tuples_list in scraped_data.items():
     csv_list = []
     unit_in_building_index = 1
     for unit_id, scraped_json in data_tuples_list: