コード例 #1
0
 def get_bill(self, bill_id, **kwargs):
     url = kwargs.pop('url')
     agenda_item = kwargs.pop('agenda_item')
     _type = self.get_type(bill_id)
     bill = Bill(bill_id, self.session, type=_type, **kwargs)
     bill.add_source(url, note='detail')
     return bill
コード例 #2
0
 def get_bill(self, bill_id, **kwargs):
     url = kwargs.pop("url")
     agenda_item = kwargs.pop("agenda_item")
     _type = self.get_type(bill_id)
     bill = Bill(bill_id, self.session, type=_type, **kwargs)
     bill.add_source(url, note="detail")
     return bill
コード例 #3
0
    def get_bill(self, bill_id, **kwargs):
        url = 'http://www.denvergov.org/sirepub/item.aspx?itemid=%s' % bill_id
        self.urls.add(detail=url)

        bill_id = kwargs.pop('number')
        bill = Bill(bill_id, self.session, kwargs['title'], 'butt',
                    type=['bills'])
        bill.add_source(url, note='detail')

        xpath = '//table[contains(@class, "history")]/tr'
        for tr in self.urls.detail.xpath(xpath):
            import pdb; pdb.set_trace()

        return bill
コード例 #4
0
    def get_bill(self, bill_id, **kwargs):
        url = 'http://www.denvergov.org/sirepub/item.aspx?itemid=%s' % bill_id
        self.urls.add(detail=url)

        bill_id = kwargs.pop('number')
        bill = Bill(bill_id,
                    self.session,
                    kwargs['title'],
                    'butt',
                    type=['bills'])
        bill.add_source(url, note='detail')

        xpath = '//table[contains(@class, "history")]/tr'
        for tr in self.urls.detail.xpath(xpath):
            import pdb
            pdb.set_trace()

        return bill
コード例 #5
0
ファイル: test_bill.py プロジェクト: lfalvarez/pupa
def toy_bill():
    b = Bill(name="HB 2017",
             session="2012A",
             title="A bill for an act to raise the cookie budget by 200%",
             organization="Foo Senate",
             type="bill")
    b.add_source("http://uri.example.com/", note="foo")
    print(b.as_dict())
    b.validate()
    return b
コード例 #6
0
ファイル: import_billy.py プロジェクト: finestjava/pupa
    def migrate_bills(self, state):
        spec = {}
        if state:
            spec['state'] = state

        bills = self.billy_db.bills.find(spec, timeout=False)
        for bill in bills:

            ocdid = _hot_cache.get('{state}-{chamber}'.format(**bill))
            org_name = name_cache.get(ocdid)
            if not org_name or not ocdid:
                raise Exception("""Can't look up chamber this legislative
                                instrument was introduced into.""")

            b = Bill(name=bill['bill_id'],
                     organization=org_name,
                     organization_id=ocdid,
                     session=bill['session'],
                     title=bill['title'],
                     chamber=bill['chamber'],
                     type=bill['type'],
                     created_at=bill['created_at'],
                     updated_at=bill['updated_at'])

            b.identifiers = [{'scheme': 'openstates',
                             'identifier': bill['_id']}]
            b._openstates_id = bill['_id']

            blacklist = ["bill_id", "session", "title", "chamber", "type",
                         "created_at", "updated_at", "sponsors", "actions",
                         "versions", "sources", "state", "action_dates",
                         "documents", "level", "country", "alternate_titles",
                         "subjects", "_id", "type", "_type", "_term", "_all_ids",
                         "summary", "_current_term", "_current_session"]

            for key, value in bill.items():
                if key in blacklist or not value:  # or key.startswith("_"):
                    continue
                b.extras[key] = value

            for subject in bill.get('subjects', []):
                b.add_subject(subject)

            if 'summary' in bill and bill['summary']:
                # OpenStates only has one at most. let's just convert it
                # blind.
                b.add_summary('summary', bill['summary'])

            if 'alternate_titles' in bill:
                b.other_titles = [{"title": x, "note": None}
                                  for x in bill['alternate_titles']]

            for source in bill['sources']:
                b.add_source(source['url'], note='OpenStates source')

            for document in bill['documents']:
                b.add_document_link(
                    mimetype=document.get('mimetype'),
                    name=document['name'],
                    url=document['url'],
                    document_id=document['doc_id'],
                    on_duplicate='ignore')  # Old docs are bad about this

            b.add_extra('action_dates', bill['action_dates'])

            for version in bill['versions']:
                kwargs = {}
                mime = version.get("mimetype", version.get("+mimetype"))
                if mime:
                    kwargs['mimetype'] = mime

                b.add_version_link(name=version['name'],
                                   url=version['url'],
                                   on_duplicate='ignore',
                                   document_id=version['doc_id'],
                                   # ^^^ Some old OS entries are not so
                                   # good about this.
                                   **kwargs)

            for subject in bill.get('subjects', []):
                b.add_subject(subject)

            for action in bill['actions']:
                related_entities = None
                related = action.get("related_entities")
                if related:
                    related_entities = []
                    for rentry in related:
                        type_ = {
                            "committee": "organizations",
                            "legislator": "people"
                        }[rentry['type']]

                        nid = rentry['id'] = lookup_entry_id(type_, rentry['id'])
                        if nid:
                            if "ocd" not in nid:
                                raise Exception("Non-OCD id")

                        rentry['_type'] = {
                            "committee": "organization",
                            "legislator": "person"
                        }[rentry.pop('type')]

                        related_entities.append(rentry)

                when = dt.datetime.strftime(action['date'], "%Y-%m-%d")

                translate = {"bill:introduced": "introduced",
                             "bill:reading:1": "reading:1",
                             "bill:reading:2": "reading:2",
                             "bill:reading:3": "reading:3"}

                type_ = [translate.get(x, None) for x in action['type']]

                b.add_action(description=action['action'],
                             actor=action['actor'],
                             date=when,
                             type=filter(lambda x: x is not None, type_),
                             related_entities=related_entities)

            for sponsor in bill['sponsors']:
                type_ = 'people'
                sponsor_id = sponsor.get('leg_id', None)

                if sponsor_id is None:
                    type_ = 'organizations'
                    sponsor_id = sponsor.get('committee_id', None)

                kwargs = {}
                if sponsor_id:
                    objid = lookup_entry_id(type_, sponsor_id)

                    if objid is not None:
                        kwargs['entity_id'] = objid

                etype = {"people": "person",
                         "organizations": "organization"}[type_]

                #if sponsor.get('official_type'):
                #    kwargs['official_type'] = sponsor['official_type']
                # Not needed???

                b.add_sponsor(
                    name=sponsor['name'],
                    sponsorship_type=sponsor['type'],
                    entity_type=etype,
                    primary=sponsor['type'] == 'primary',
                    chamber=sponsor.get('chamber', None),
                    **kwargs)

            self.save_object(b)
コード例 #7
0
    def get_bills(self):
        for i, page in enumerate(self.searchLegislation()) :
            for legislation_summary in self.parseSearchResults(page) :
                title = legislation_summary['Title'].strip()
                if title == "":
                    continue

                bill = Bill(name=legislation_summary['Record #'],
                            session=self.session,
                            title=title,
                            type=[legislation_summary['Type'].lower()],
                            organization=self.jurisdiction.name)

                bill.add_source(legislation_summary['URL'])

                legislation_details = self.expandLegislationSummary(legislation_summary)

                for related_bill in legislation_details.get('Related files', []) :
                    bill.add_related_bill(name = related_bill,
                                          session = self.session,
                                          relation='other-session',
                                          chamber=None)

                for i, sponsor in enumerate(legislation_details.get('Sponsors', [])) :
                    if i == 0 :
                        primary = True
                        sponsorship_type = "Primary"
                    else :
                        primary = False
                        sponsorship_type = "Regular"

                    bill.add_sponsor(sponsor, sponsorship_type,
                                     'person', primary)

                for subject in legislation_details.get(u'Topics', []) :
                    bill.add_subject(subject)

                for attachment in legislation_details.get(u'Attachments', []) :
                    bill.add_version_link('PDF',
                                          attachment['url'],
                                          mimetype="application/pdf")


                yield bill
コード例 #8
0
    def get_bills(self):
        for i, page in enumerate(self.searchLegislation()):
            for legislation_summary in self.parseSearchResults(page):
                title = legislation_summary['Title'].strip()
                if title == "":
                    continue

                bill = Bill(name=legislation_summary['Record #'],
                            session=self.session,
                            title=title,
                            type=[legislation_summary['Type'].lower()],
                            organization=self.jurisdiction.name)

                bill.add_source(legislation_summary['URL'])

                legislation_details = self.expandLegislationSummary(
                    legislation_summary)

                for related_bill in legislation_details.get(
                        'Related files', []):
                    bill.add_related_bill(name=related_bill,
                                          session=self.session,
                                          relation='other-session',
                                          chamber=None)

                for i, sponsor in enumerate(
                        legislation_details.get('Sponsors', [])):
                    if i == 0:
                        primary = True
                        sponsorship_type = "Primary"
                    else:
                        primary = False
                        sponsorship_type = "Regular"

                    bill.add_sponsor(sponsor, sponsorship_type, 'person',
                                     primary)

                for subject in legislation_details.get(u'Topics', []):
                    bill.add_subject(subject)

                for attachment in legislation_details.get(u'Attachments', []):
                    bill.add_version_link('PDF',
                                          attachment['url'],
                                          mimetype="application/pdf")

                yield bill