@app.route('/', defaults={'page': 1, 'service_code': ''})
@app.route('/<int:page>', defaults={'service_code': ''})
@app.route('/<int:page>/<service_code>')
def index(page, service_code):
    if ('filter' in request.args):
        service_code = request.args['filter']
    url = ('%s/requests.json' % app.config['OPEN311_SERVER'])
    recent_sr_timeframe = app.config.get('RECENT_SRS_TIME')
    page_size = app.config.get('SRS_PAGE_SIZE')
    paged = (page_size > 0)
    if (not paged):
        page_size = app.config.get('MAX_RECENT_SRS', 50)
        page = 1
    services_list = open311tools.services(app.config['OPEN311_SERVER'], app.config['OPEN311_API_KEY'])
    service_name = ''
    for service in services_list:
        if (service_code == service['service_code']):
            service_name = service['service_name']
            break
    if (not service_name):
        service_code = ''
    params = {'extensions': 'true', 'page_size': page_size, 'page': page, 'service_code': service_code}
    if recent_sr_timeframe:
        start_datetime = (datetime.datetime.utcnow() - datetime.timedelta(seconds=recent_sr_timeframe))
        params['start_date'] = (start_datetime.isoformat() + 'Z')
    if app.config['OPEN311_API_KEY']:
        params['api_key'] = app.config['OPEN311_API_KEY']
    r = requests.get(url, params=params)
    if (r.status_code != 200):
        app.logger.error('OPEN311: Failed to load recent requests from Open311 server. Status Code: %s, Response: %s', r.status_code, r.text)
        service_requests = None
    else:
        service_requests = r.json[:page_size]
        now = datetime.datetime.utcnow()
        for sr in service_requests:
            if ('updated_datetime' in sr):
                updated = iso8601.parse_date(sr['updated_datetime']).astimezone(pytz.utc).replace(tzinfo=None)
                sr['updated_datetime'] = min(now, updated)
    return render_app_template('index.html', service_requests=service_requests, page=page, services_list=services_list, service_code=service_code, service_name=service_name)
@app.route('/', defaults={'page': 1, 'service_code': })
@app.route('/<int:page>', defaults={'service_code': })
@app.route('/<int:page>/<service_code>')
def index(page, service_code):
    if ('filter' in request.args):
        service_code = request.args['filter']
    url = ('%s/requests.json' % app.config['OPEN311_SERVER'])
    recent_sr_timeframe = app.config.get('RECENT_SRS_TIME')
    page_size = app.config.get('SRS_PAGE_SIZE')
    paged = (page_size > 0)
    if (not paged):
        page_size = app.config.get('MAX_RECENT_SRS', 50)
        page = 1
    services_list = open311tools.services(app.config['OPEN311_SERVER'], app.config['OPEN311_API_KEY'])
    service_name = 
    for service in services_list:
        if (service_code == service['service_code']):
            service_name = service['service_name']
            break
    if (not service_name):
        service_code = 
    params = {'extensions': 'true', 'page_size': page_size, 'page': page, 'service_code': service_code}
    if recent_sr_timeframe:
        start_datetime = (datetime.datetime.utcnow() - datetime.timedelta(seconds=recent_sr_timeframe))
        params['start_date'] = (start_datetime.isoformat() + 'Z')
    if app.config['OPEN311_API_KEY']:
        params['api_key'] = app.config['OPEN311_API_KEY']
    r = requests.get(url, params=params)
    if (r.status_code != 200):
        app.logger.error('OPEN311: Failed to load recent requests from Open311 server. Status Code: %s, Response: %s', r.status_code, r.text)
        service_requests = None
    else:
        service_requests = r.json[:page_size]
        now = datetime.datetime.utcnow()
        for sr in service_requests:
            if ('updated_datetime' in sr):
                updated = iso8601.parse_date(sr['updated_datetime']).astimezone(pytz.utc).replace(tzinfo=None)
                sr['updated_datetime'] = min(now, updated)
    return render_app_template('index.html', service_requests=service_requests, page=page, services_list=services_list, service_code=service_code, service_name=service_name)