opencivicdata / scrapers-us-municipal

Scrapers for US municipal governments.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Write a self-sufficient method for detecting LA Metro legislative session

hancush opened this issue · comments

The current method for determining the legislative session for a bill depends on hard-coding new years in:

    def session(self, action_date) :
        localize = pytz.timezone(self.TIMEZONE).localize
        if action_date <  localize(datetime.datetime(2015, 7, 1)) :
            return "2014"
        if action_date <  localize(datetime.datetime(2016, 7, 1)) :
            return "2015"
        if action_date <  localize(datetime.datetime(2017, 7, 1)) :
            return "2016"
        if action_date <  localize(datetime.datetime(2018, 7, 1)) :
            return "2017"                 
        else:
            raise ValueError("Invalid action date: {}".format(action_date))

I propose revisiting this logic so we don't have to update it every July. Since the legislative session corresponding to the current year begins July 1, we could use logic like:

# First legislative session began July 1, 2014
if (action date >= July 1, 2014) and (year from action date <= current year):
    if action date < July 1: 
        return year from action date - 1 
    else:
        return year from action date
else:
    raise ValueError('Invalid year')

– perhaps enforcing the floor a bit more intelligently. 😅

Looking at the other scrapers, it seems conventional to manually add new sessions. (Not least of all, we need to account for new sessions in Councilmatic instances downstream, so it's good to know when one rolls around.)

Recently merged a PR so new legislative sessions need only be added in one place for Metro (#229). Closing this for now.