Ejemplo n.º 1
0
    def load_data(self, since=None):

        if not since:
            res = self.db.upcoming_bills.aggregate({'$group': {'_id': '', 'last': {'$max': '$legislative_day'}}})
            since = res['result'][0]['last'] if res['result'] else yesterday()

        for bill in congress.upcoming_bills(legislative_day__gte=since.date().isoformat(), fields='bill_id,legislative_day,range,chamber', per_page=200):
            if bill['legislative_day']:

                sponsor_id = list(congress.bills(bill_id=bill['bill_id'], fields='sponsor_id'))[0]['sponsor_id']

                bill['legislative_day'] = parse_date(bill['legislative_day'])
                spec = {
                    'bill_id': bill['bill_id'],
                    'legislative_day': bill['legislative_day'],
                    'chamber': bill.get('chamber')
                }
                if self.db.upcoming_bills.find_one(spec) is None:
                    obj = self.db.UpcomingBill()
                    obj.bill_id = bill['bill_id']
                    obj.legislative_day = bill['legislative_day']
                    obj.sponsor_id = sponsor_id
                    obj.range = bill['range']
                    obj.chamber = bill.get('chamber')
                    obj.save()
Ejemplo n.º 2
0
    def load_data(self, since=None):

        if not since:
            res = self.db.bill_actions.aggregate(
                {'$group': {
                    '_id': '',
                    'last': {
                        '$max': '$acted_at'
                    }
                }})
            since = res['result'][0]['last'] if res['result'] else yesterday()

        for bill in congress.bills(
                last_action_at__gte=since.date().isoformat(),
                fields='bill_id,actions',
                per_page=200):
            for action in bill['actions']:
                action['acted_at'] = parse_date(action['acted_at'])

                if self.db.bill_actions.find_one({
                        'bill_id': bill['bill_id'],
                        'acted_at': action['acted_at'],
                        'type': action['type']
                }) is None:

                    obj = self.db.BillAction()
                    obj.bill_id = bill['bill_id']
                    obj.acted_at = action['acted_at']
                    obj.type = action['type']
                    obj.roll_id = action.get('roll_id')
                    if 'committees' in action:
                        obj.committee_ids = sorted(
                            c['committee_id'] for c in action['committees'])
                    obj.save()
Ejemplo n.º 3
0
    def load_data(self, since=None):

        if not since:
            res = self.db.bills.aggregate(
                {'$group': {
                    '_id': '',
                    'last': {
                        '$max': '$introduced_on'
                    }
                }})
            since = res['result'][0]['last'] if res['result'] else yesterday()

        count = 0

        for bill in congress.bills(introduced_on__gte=since.date().isoformat(),
                                   fields='bill_id,sponsor_id,introduced_on',
                                   per_page=200):
            if self.db.bills.find_one({'bill_id': bill['bill_id']}) is None:
                obj = self.db.Bill()
                obj.bill_id = bill['bill_id']
                obj.sponsor_id = bill['sponsor_id']
                obj.introduced_on = parse_date(bill['introduced_on'])
                obj.save()

                count += 1

        logger.info('loaded %d bills' % count)
	def cosponsored(self, score_adjustment, bill_id, cosponsorship_test=lambda x: True):
		""" Tests whether each legislator sponsored or cosponsored a bill, with optional test """
		(adjustment_desc, adjustment) = self._get_adjustment_desc(score_adjustment)

		bill = congress.bills(bill_id=bill_id, fields='cosponsor_ids,sponsor_id')[0]
		cosponsors = congress.bills(bill_id=bill_id, fields='cosponsors')
		valid_sponsor_cosponsor_ids = [bill['sponsor_id']]
		
		for cs in cosponsors[0]['cosponsors']:
			if cosponsorship_test(cs):
				valid_sponsor_cosponsor_ids.append(cs['legislator']['bioguide_id'])
		
		for legislator in self.scores:
			score = 0
			if legislator in valid_sponsor_cosponsor_ids:
				score = adjustment
			self.scores[legislator]['%s (%s%s)' % (adjustment_desc, (adjustment > 0) and '+' or '', adjustment)] = score		
Ejemplo n.º 5
0
    def cosponsored(self, score_adjustment, bill_id, cosponsorship_test=lambda x: True):
        """ Tests whether each legislator sponsored or cosponsored a bill, with optional test """
        (adjustment_desc, adjustment) = self._get_adjustment_desc(score_adjustment)

        bill = congress.bills(bill_id=bill_id, fields="cosponsor_ids,sponsor_id")[0]
        cosponsors = congress.bills(bill_id=bill_id, fields="cosponsors")
        valid_sponsor_cosponsor_ids = [bill["sponsor_id"]]

        for cs in cosponsors[0]["cosponsors"]:
            if cosponsorship_test(cs):
                valid_sponsor_cosponsor_ids.append(cs["legislator"]["bioguide_id"])

        for legislator in self.scores:
            score = 0
            if legislator in valid_sponsor_cosponsor_ids:
                score = adjustment
            self.scores[legislator]["%s (%s%s)" % (adjustment_desc, (adjustment > 0) and "+" or "", adjustment)] = score
def fetch_bills_info():
    """
    downlaods bill metadata from the sunlight api
    currently it downloads all the bills available in sunlight api
    consider supporting other filters in the future, like time ..etc
    """
    congress = Congress()
    congress = PagingService(congress)
    results = list (congress.bills(fields="versions,history,title,urls,id" ,limit=sys.maxint  ) )
    return results
Ejemplo n.º 7
0
    def setup(self):
        self.service = BillService(self.db)
        self.service.load_data()

        if self.db.bills.count() == 0:
            last_bills = congress.bills(order='introduced_on', fields='bill_id,sponsor_id,introduced_on', per_page=20)
            for bill in last_bills:
                obj = self.db.Bill()
                obj.bill_id = bill['bill_id']
                obj.sponsor_id = bill['sponsor_id']
                obj.introduced_on = parse_date(bill['introduced_on'])
                obj.save()
Ejemplo n.º 8
0
    def setup(self):
        self.service = BillService(self.db)
        self.service.load_data()

        if self.db.bills.count() == 0:
            last_bills = congress.bills(
                order='introduced_on',
                fields='bill_id,sponsor_id,introduced_on',
                per_page=20)
            for bill in last_bills:
                obj = self.db.Bill()
                obj.bill_id = bill['bill_id']
                obj.sponsor_id = bill['sponsor_id']
                obj.introduced_on = parse_date(bill['introduced_on'])
                obj.save()
Ejemplo n.º 9
0
    def load_data(self, since=None):

        if not since:
            res = self.db.bills.aggregate({'$group': {'_id': '', 'last': {'$max': '$introduced_on'}}})
            since = res['result'][0]['last'] if res['result'] else yesterday()

        count = 0

        for bill in congress.bills(introduced_on__gte=since.date().isoformat(), fields='bill_id,sponsor_id,introduced_on', per_page=200):
            if self.db.bills.find_one({'bill_id': bill['bill_id']}) is None:
                obj = self.db.Bill()
                obj.bill_id = bill['bill_id']
                obj.sponsor_id = bill['sponsor_id']
                obj.introduced_on = parse_date(bill['introduced_on'])
                obj.save()

                count += 1

        logger.info('loaded %d bills' % count)
Ejemplo n.º 10
0
    def load_data(self, since=None):

        if not since:
            res = self.db.bill_actions.aggregate({'$group': {'_id': '', 'last': {'$max': '$acted_at'}}})
            since = res['result'][0]['last'] if res['result'] else yesterday()

        for bill in congress.bills(last_action_at__gte=since.date().isoformat(), fields='bill_id,actions', per_page=200):
            for action in bill['actions']:
                action['acted_at'] = parse_date(action['acted_at'])

                if self.db.bill_actions.find_one({'bill_id': bill['bill_id'], 'acted_at': action['acted_at'], 'type': action['type']}) is None:

                    obj = self.db.BillAction()
                    obj.bill_id = bill['bill_id']
                    obj.acted_at = action['acted_at']
                    obj.type = action['type']
                    obj.roll_id = action.get('roll_id')
                    if 'committees' in action:
                        obj.committee_ids = sorted(c['committee_id'] for c in action['committees'])
                    obj.save()
Ejemplo n.º 11
0
    def load_data(self, since=None):

        if not since:
            res = self.db.upcoming_bills.aggregate(
                {'$group': {
                    '_id': '',
                    'last': {
                        '$max': '$legislative_day'
                    }
                }})
            since = res['result'][0]['last'] if res['result'] else yesterday()

        for bill in congress.upcoming_bills(
                legislative_day__gte=since.date().isoformat(),
                fields='bill_id,legislative_day,range,chamber',
                per_page=200):
            if bill['legislative_day']:

                sponsor_id = list(
                    congress.bills(bill_id=bill['bill_id'],
                                   fields='sponsor_id'))[0]['sponsor_id']

                bill['legislative_day'] = parse_date(bill['legislative_day'])
                spec = {
                    'bill_id': bill['bill_id'],
                    'legislative_day': bill['legislative_day'],
                    'chamber': bill.get('chamber')
                }
                if self.db.upcoming_bills.find_one(spec) is None:
                    obj = self.db.UpcomingBill()
                    obj.bill_id = bill['bill_id']
                    obj.legislative_day = bill['legislative_day']
                    obj.sponsor_id = sponsor_id
                    obj.range = bill['range']
                    obj.chamber = bill.get('chamber')
                    obj.save()
Ejemplo n.º 12
0
def get_recent_bills():
    bills_list = congress.bills()

    return [bill.Bill(bill_json) for bill_json in bills_list]