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


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

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


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

示例1: scrape_details

# 需要导入模块: from pupa.scrape import Person [as 别名]
# 或者: from pupa.scrape.Person import extras['org_info'] [as 别名]
    def scrape_details(self, chamber, leg_name, leg_link, role):
        if not leg_link:
            # Vacant post, likely:
            if "Vacancy" in leg_name:
                return
            raise Exception("leg_link is null. something went wrong")
        try:
            url = 'http://billstatus.ls.state.ms.us/members/%s' % leg_link
            url_root = os.path.dirname(url)
            details_page = self.get(url)
            root = lxml.etree.fromstring(details_page.content)
            party = root.xpath('string(//PARTY)')

            district = root.xpath('string(//DISTRICT)')

            photo = "%s/%s" % (url_root, root.xpath('string(//IMG_NAME)'))

            home_phone = root.xpath('string(//H_PHONE)')

            home_address = root.xpath('string(//H_ADDRESS)')
            home_address2 = root.xpath('string(//H_ADDRESS2)')
            home_city = root.xpath('string(//H_CITY)')
            home_zip = root.xpath('string(//H_ZIP)')

            home_address_total = ''
            if home_address and home_city:
                if not home_address2:
                    home_address_total = "%s\n%s, MS %s" % (
                        home_address,
                        home_city,
                        home_zip
                    )
                else:
                    home_address_total = "%s\n%s\n%s, MS %s" % (
                        home_address,
                        home_address2,
                        home_city,
                        home_zip
                    )

            # bis_phone = root.xpath('string(//B_PHONE)')
            capital_phone = root.xpath('string(//CAP_PHONE)')
            # other_phone = root.xpath('string(//OTH_PHONE)')
            org_info = root.xpath('string(//ORG_INFO)')
            email_name = root.xpath('string(//EMAIL_ADDRESS)').strip()
            cap_room = root.xpath('string(//CAP_ROOM)')

            if leg_name in ('Lataisha Jackson', 'John G. Faulkner', 'Jeffery Harness'):
                assert not party, ("Remove special-casing for this Democrat without a "
                                   "listed party: {}").format(leg_name)
                party = 'Democratic'
            elif leg_name in ('James W. Mathis',
                              'John Glen Corley'):
                assert not party, ("Remove special-casing for this Republican without"
                                   " a listed party: {}").format(leg_name)
                party = 'Republican'
            elif party == 'D':
                party = 'Democratic'
            elif party == 'R':
                party = 'Republican'
            else:
                raise AssertionError(
                    "A member with no identifiable party was found: {}".format(leg_name))
            leg = Person(primary_org=chamber,
                         district=district,
                         party=party,
                         image=photo,
                         name=leg_name,
                         role=role
                         )
            leg.extras['org_info'] = org_info
            leg.add_source(url)
            leg.add_link(url)

            if email_name != "":
                if "@" in email_name:
                    email = email_name
                else:
                    email = '%[email protected]%s.ms.gov' % (email_name,
                                              {"upper": "senate", "lower": "house"}[chamber])
                leg.add_contact_detail(type='email', value=email, note='Capitol Office')

            if capital_phone != "":
                leg.add_contact_detail(type='voice', value=capital_phone, note='Capitol Office')

            if cap_room != "":
                address = "Room %s\n%s" % (cap_room, CAP_ADDRESS)
            else:
                address = CAP_ADDRESS
            leg.add_contact_detail(type='address', value=address, note='Capitol Office')

            if home_phone != "":
                leg.add_contact_detail(type='voice', value=home_phone, note='District Office')

            if home_address_total != "":
                leg.add_contact_detail(type='address',
                                       value=home_address_total,
                                       note='District Office')

            yield leg
#.........这里部分代码省略.........
开发者ID:sunlightlabs,项目名称:openstates,代码行数:103,代码来源:people.py


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