本文整理汇总了Python中pupa.scrape.Person.extras['number_children']方法的典型用法代码示例。如果您正苦于以下问题:Python Person.extras['number_children']方法的具体用法?Python Person.extras['number_children']怎么用?Python Person.extras['number_children']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pupa.scrape.Person
的用法示例。
在下文中一共展示了Person.extras['number_children']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scrape_chamber
# 需要导入模块: from pupa.scrape import Person [as 别名]
# 或者: from pupa.scrape.Person import extras['number_children'] [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