Exemplo n.º 1
0
def get_session_days(session=None, json=False):
    """ Given the start and end date of the session, get the days there
        were actions on legislation.
        """
    if not session:
        session = app.session
    session_dates = app.session_dates[session]
    # session_dates will look something like [date(2016,1,13), date(2016,5,11)]

    # If we're dealing with the current session, we don't want to return dates
    # in the future.
    today = date.today()
    if today < session_dates[1]:
        session_dates[1] = today

    q = BillQuery()
    q.filter_session(session)

    days = []
    current_issue = session_dates[0]
    while current_issue <= session_dates[1]:
        # Make sure something happened on this day.
        date_range = [current_issue, current_issue]
        bills = q.filter_by_date(date_range, 'ALL')
        if len(bills) > 0:
            if json == True:
                days.append(current_issue.__str__())
            else:
                days.append(current_issue)

        current_issue = current_issue + timedelta(1)
    return days
Exemplo n.º 2
0
def index():
    app.page['title'] = 'Colorado Bill Tracker'
    app.page[
        'description'] = 'Tracking legislation, legislators and committees in the Colorado General Assembly. Updated daily.'
    app.page['url'] = build_url(app, request)

    q = BillQuery()
    q.items = q.filter_session(app.session)

    days_back = 0
    bills = []
    finish = date.today()
    start = finish - timedelta(days_back)
    while True:
        bills = q.filter_by_date([start, finish], 'last')
        if len(bills) > 0:
            break
        if days_back > 300:
            break
        days_back += 1
        start = finish - timedelta(days_back)

    response = {
        'app': app,
        'bills': bills,
        'signed': q.filter_action_dates('signed'),
        'introduced': q.filter_action_dates('first'),
        'passed_upper': q.filter_action_dates('passed_upper'),
        'passed_lower': q.filter_action_dates('passed_lower'),
        'days_back': days_back,
        'back_date': date.today() - timedelta(days_back)
    }
    return render_template('home.html', response=response)
Exemplo n.º 3
0
def session_index(js=''):
    app.page['title'] = 'Search Colorado General Assembly legislation'
    app.page[
        'description'] = 'An index of Colorado legislative sessions we have bills for. Also, search all bills. Also, use our Bill Generator.'
    app.page['url'] = build_url(app, request)

    q = BillQuery()
    data = {'bills': q.items}

    # We return a lighter version of the bills dict for generating the javascript.
    data['bills_light'] = []
    for item in data['bills']:
        url = 'http://extras.denverpost.com/app/bill-tracker/bills/%s/%s/' % (
            item['session'].lower(), item['bill_id'].replace(' ', '_').lower())
        d = {'title': item['title'], 'url': url, 'session': item['session']}
        data['bills_light'].append(d)

    response = {
        'app': app,
        'data': data,
        'json': json.dumps(data['bills_light']),
    }

    fn = 'session_index.html'
    if js == 'js':
        fn = fn.replace('.html', '.js')
    return render_template(fn, response=response)
Exemplo n.º 4
0
def session_passed_detail(session, passfail, chamber):
    if session not in app.sessions:
        abort(404)
    app.page[
        'title'] = 'Legislation that %s the %s chamber in the %s session' % (
            passfail, chamber, session)
    app.page['description'] = ''
    app.page['url'] = build_url(app, request)

    q = BillQuery()
    q.session = session.upper()
    q.filter_session()
    data = {
        'upper': q.filter_action_dates('passed_upper'),
        'lower': q.filter_action_dates('passed_lower'),
    }
    if passfail == 'failed':
        data = {
            'upper': q.filter_failed(),
            'lower': q.filter_failed(),
        }
    response = {
        'app': app,
        'session': session,
        'passfail': passfail,
        'chamber': chamber,
        'data': data
    }
    return render_template('session_passed_detail.html', response=response)
Exemplo n.º 5
0
def session_detail(session, js='', csv=''):
    if session not in app.sessions:
        abort(404)
    app.page['title'] = 'Session %s' % session
    app.page['description'] = ''
    app.page['url'] = build_url(app, request)

    q = BillQuery()
    q.filter_session(session.upper())
    data = {'bills': q.filter_action_dates('first')}

    # Clean up the json for delivering to datatables.
    # Datatables requires all fields be present in all items,
    # which means we need to add vote fields for the bills that haven't
    # been voted on yet.
    bills = []
    for item in data['bills']:
        if 'votes' not in item:
            item['votes'] = []
        if 'sources' not in item:
            item['sources'] = []
        bills.append(item)

    # We return a lighter version of the bills dict for generating the javascript.
    data['bills_light'] = []
    for item in data['bills']:
        url = 'http://extras.denverpost.com/app/bill-tracker/bills/%s/%s/' % (
            item['session'].lower(), item['bill_id'].replace(' ', '_').lower())
        d = {'title': item['title'], 'url': url}
        data['bills_light'].append(d)

    response = {
        'app': app,
        'session': session,
        'json': json.dumps(bills),
        'data': data
    }

    fn = 'session_detail.html'
    if js == 'js':
        fn = fn.replace('.html', '.js')
    elif csv == 'csv':
        fn = fn.replace('.html', '.csv')
    return render_template(fn, response=response)
Exemplo n.º 6
0
def session_signed_detail(session):
    if session not in app.sessions:
        abort(404)

    app.page[
        'title'] = 'Legislation Colorado\'s governor signed into law in the %s session' % session
    app.page[
        'description'] = 'A list of legislation passed into law in the %s session' % session
    app.page['url'] = build_url(app, request)

    q = BillQuery()
    q.session = session.upper()
    q.filter_session()
    data = {
        'bills': q.filter_action_dates('signed'),
    }
    response = {
        'app': app,
        'data': data,
        'session': session,
    }
    return render_template('session_signed_detail.html', response=response)
Exemplo n.º 7
0
def week_detail(issue_date):
    app.page['title'] = 'The Week in Colorado legislature, '
    app.page[
        'description'] = 'A round-up of what happened to which legislation in Colorado\'s state legislature for the week ending '
    app.page['url'] = build_url(app, request)

    # Make sure it's a valid week
    current_issue = app.theweek[app.session]
    today = date.today()
    weeks = []
    while current_issue <= today:
        weeks.append(current_issue.__str__())
        current_issue = current_issue + timedelta(7)

    # Get the previous and next days.
    # The beginning and end of the list won't have prev/nexts, so we write
    # logic to make sure we don't throw an error over that.
    pos = weeks.index(issue_date)
    if pos == 0:
        if len(weeks) == 1:
            prev_next = [None, None]
        else:
            prev_next = [None, weeks[pos + 1]]
    elif pos == len(weeks) - 1:
        prev_next = [weeks[pos - 1], None]
    else:
        prev_next = [weeks[pos - 1], weeks[pos + 1]]

    # Turn the date into a range
    the_date = datetime.strptime(issue_date, '%Y-%m-%d')
    start, finish = the_date - timedelta(7), the_date
    date_range = [start.date(), finish.date()]

    app.page['description'] += '%s' % datetime.strftime(the_date, '%B %-d %Y')
    app.page['title'] += '%s' % datetime.strftime(the_date, '%B %-d %Y')

    if issue_date not in weeks:
        abort(404)

    # Get a json file of the recent legislative news
    news = []
    try:
        news = json.load(open('_input/news/articles_%s_8.json' % issue_date))
    except:
        try:
            news = json.load(
                open('_input/news/articles_%s_7.json' % issue_date))
        except:
            news = []

    q = BillQuery()
    q.filter_session(app.session)
    response = {
        'app':
        app,
        'issue_date':
        issue_date,
        'prev_next':
        prev_next,
        'news':
        news,
        'signed':
        q.filter_by_date(date_range, 'signed',
                         q.filter_action_dates('signed')),
        'introduced':
        q.filter_by_date(date_range, 'first', q.filter_action_dates('first')),
        'passed_upper':
        q.filter_by_date(date_range, 'passed_upper',
                         q.filter_action_dates('passed_upper')),
        'passed_lower':
        q.filter_by_date(date_range, 'passed_lower',
                         q.filter_action_dates('passed_lower')),
    }
    return render_template('week_detail.html', response=response)
Exemplo n.º 8
0
def day_detail(issue_date):
    app.page['title'] = 'in the Colorado state legislature'
    app.page[
        'description'] = 'A round-up of the news, the bills passed, signed and introduced in the Colorado General Assembly on '
    app.page['url'] = build_url(app, request)

    # Make sure it's a valid day
    the_date = datetime.strptime(issue_date, '%Y-%m-%d')
    the_news_date = the_date + timedelta(1)
    date_range = [the_date.date(), the_date.date()]
    days = json.load(open('_input/days_%s.json' % app.session))
    if issue_date not in days:
        abort(404)

    # Get the previous and next days.
    # The beginning and end of the list won't have prev/nexts, so we write
    # logic to make sure we don't throw an error over that.
    pos = days.index(issue_date)
    if pos == 0:
        prev_next = [None, days[pos + 1]]
    elif pos == len(days) - 1:
        prev_next = [days[pos - 1], None]
    else:
        prev_next = [days[pos - 1], days[pos + 1]]

    app.page['title'] = '%s %s' % (datetime.strftime(
        the_date, '%B %-d %Y'), app.page['title'])
    app.page['description'] += '%s' % datetime.strftime(the_date, '%B %-d %Y')

    # Get a json file of the recent legislative news
    news = []
    try:
        #news = json.load(open('_input/news/articles_%s_1.json' % the_date.__str__()))
        news = json.load(open('_input/news/articles_%s_1.json' % issue_date))
    except:
        pass

    q = BillQuery()
    q.filter_session(app.session)
    response = {
        'app':
        app,
        'issue_date':
        issue_date,
        'prev_next':
        prev_next,
        'news':
        news,
        'signed':
        q.filter_by_date(date_range, 'signed',
                         q.filter_action_dates('signed')),
        'introduced':
        q.filter_by_date(date_range, 'first', q.filter_action_dates('first')),
        'passed_upper':
        q.filter_by_date(date_range, 'passed_upper',
                         q.filter_action_dates('passed_upper')),
        'passed_lower':
        q.filter_by_date(date_range, 'passed_lower',
                         q.filter_action_dates('passed_lower')),
    }
    return render_template('day_detail.html', response=response)