当前位置: 首页>>代码示例>>Python>>正文


Python Person.extras['civic_organizations']方法代码示例

本文整理汇总了Python中pupa.scrape.Person.extras['civic_organizations']方法的典型用法代码示例。如果您正苦于以下问题:Python Person.extras['civic_organizations']方法的具体用法?Python Person.extras['civic_organizations']怎么用?Python Person.extras['civic_organizations']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pupa.scrape.Person的用法示例。


在下文中一共展示了Person.extras['civic_organizations']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: scrape_chamber

# 需要导入模块: from pupa.scrape import Person [as 别名]
# 或者: from pupa.scrape.Person import extras['civic_organizations'] [as 别名]
    def scrape_chamber(self, chamber, session):
        chamber_abbrev = {'upper': 'S', 'lower': 'H'}[chamber]

        url = "https://wyoleg.gov/LsoService/api/legislator/2018/{}".format(
            chamber_abbrev)

        response = self.get(url)
        people_json = json.loads(response.content.decode('utf-8'))

        for row in people_json:

            # some fields are only available in the list json, some only in the details call
            details_url = 'https://wyoleg.gov/LsoService/api/legislator/{}'.format(
                row['legID'])
            details_response = self.get(details_url)
            details = json.loads(details_response.content.decode('utf-8'))

            party = self.party_map[row['party']]

            if details['dob'] is not None:
                dob = datetime.datetime.strptime(
                    details['dob'], '%m/%d/%Y %I:%M:%S %p')
                dob_str = datetime.datetime.strftime(dob, "%Y-%m-%d")
            else:
                dob_str = ''

            photo_url = 'http://wyoleg.gov/LegislatorSummary/Photos/{}'.format(
                details['legPhoto'])

            person = Person(
                name=row['name'],
                district=row['district'].lstrip('SH0'),
                party=party,
                primary_org=chamber,
                birth_date=dob_str,
                image=photo_url,
            )

            if details['address']:
                address = '{}, {} {} {}'.format(
                    details['address'],
                    details['city'],
                    details['state'],
                    details['zip']
                )
                person.add_contact_detail(type='address', value=address)

            if row['eMail']:
                person.add_contact_detail(type='email', value=row['eMail'])

            if row['phone']:
                person.add_contact_detail(type='voice', value=row['phone'])

            person.extras['wy_leg_id'] = row['legID']
            person.extras['county'] = row['county']
            person.extras['given_name'] = row['firstName']
            person.extras['family_name'] = row['lastName']
            person.extras['religion'] = details['religion']
            person.extras['number_children'] = details['noChildren']
            person.extras['spouse_given_name'] = details['spouseName']
            person.extras['place_of_birth'] = details['birthPlace']
            person.extras['occupation'] = details['occupationDesc']

            if details['legEducation']:
                person.extras['education'] = details['legEducation']

            if details['civicOrgs']:
                person.extras['civic_organizations'] = details['civicOrgs']

            # http://wyoleg.gov/Legislators/2018/S/2032
            leg_url = 'http://wyoleg.gov/Legislators/{}/{}/{}'.format(
                session,
                row['party'],
                row['legID'])

            person.add_source(leg_url)
            person.add_link(leg_url)

            yield person
开发者ID:sunlightlabs,项目名称:openstates,代码行数:81,代码来源:people.py


注:本文中的pupa.scrape.Person.extras['civic_organizations']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。