本文整理汇总了Python中pupa.scrape.Organization.add_post方法的典型用法代码示例。如果您正苦于以下问题:Python Organization.add_post方法的具体用法?Python Organization.add_post怎么用?Python Organization.add_post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pupa.scrape.Organization
的用法示例。
在下文中一共展示了Organization.add_post方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self):
organization = Organization(self.name, classification=self.classification)
leader_role = styles_of_address[self.division_id]['Leader']
member_role = self.member_role or styles_of_address[self.division_id]['Member']
parent = Division.get(self.division_id)
# Don't yield posts for premiers.
if parent._type not in ('province', 'territory'):
# Yield posts to allow ca_on_toronto to make changes.
post = Post(role=leader_role, label=parent.name, division_id=parent.id, organization_id=organization._id)
yield post
children = [child for child in parent.children() if child._type != 'place' and child._type not in self.exclude_types]
for child in children:
if not self.skip_null_valid_from and not child.attrs.get('validFrom') or child.attrs.get('validFrom') and (child.attrs['validFrom'] <= datetime.now().strftime('%Y-%m-%d') or child.attrs['validFrom'] == self.valid_from):
if self.use_type_id:
label = child.id.rsplit('/', 1)[1].capitalize().replace(':', ' ')
else:
label = child.name
# Yield posts to allow ca_on_toronto to make changes.
post = Post(role=member_role, label=label, division_id=child.id, organization_id=organization._id)
yield post
if not children and parent.attrs['posts_count']:
for i in range(1, int(parent.attrs['posts_count'])): # exclude Mayor
organization.add_post(role=member_role, label='{} (seat {})'.format(parent.name, i), division_id=parent.id)
yield organization
示例2: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self):
legislature_name = "Hawaii State Legislature"
lower_chamber_name = "House"
lower_seats = 51
lower_title = "Representative"
upper_chamber_name = "Senate"
upper_seats = 25
upper_title = "Senator"
legislature = Organization(name=legislature_name,
classification="legislature")
upper = Organization(upper_chamber_name, classification='upper',
parent_id=legislature._id)
lower = Organization(lower_chamber_name, classification='lower',
parent_id=legislature._id)
for n in range(1, upper_seats + 1):
upper.add_post(
label=str(n), role=upper_title,
division_id='{}/sldu:{}'.format(self.division_id, n))
for n in range(1, lower_seats + 1):
lower.add_post(
label=str(n), role=lower_title,
division_id='{}/sldl:{}'.format(self.division_id, n))
yield legislature
yield upper
yield lower
示例3: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self):
""" generator to obtain organization data. """
legislature_name = "South Carolina Legislature"
lower_chamber_name = "House"
lower_seats = 124
lower_title = "Representative"
upper_chamber_name = "Senate"
upper_seats = 46
upper_title = "Senator"
legislature = Organization(name=legislature_name,
classification="legislature")
upper = Organization(upper_chamber_name, classification='upper',
parent_id=legislature._id)
lower = Organization(lower_chamber_name, classification='lower',
parent_id=legislature._id)
for n in range(1, upper_seats + 1):
upper.add_post(
label=str(n), role=upper_title,
division_id='{}/sldu:{}'.format(self.division_id, n))
for n in range(1, lower_seats + 1):
lower.add_post(
label=str(n), role=lower_title,
division_id='{}/sldl:{}'.format(self.division_id, n))
yield legislature
yield upper
yield lower
示例4: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self):
exclude_type_ids = getattr(self, 'exclude_type_ids', [])
use_type_id = getattr(self, 'use_type_id', False)
organization = Organization(self.name, classification=self.classification)
parent = Division.get(self.division_id)
if parent._type not in ('province', 'territory'):
post = Post(role=styles_of_address[self.division_id]['Leader'], label=parent.name, division_id=parent.id, organization_id=organization._id)
yield post
children = [child for child in parent.children() if child._type != 'place' and child._type not in exclude_type_ids]
for child in children:
if child:
if use_type_id:
label = child.id.rsplit('/', 1)[1].capitalize().replace(':', ' ')
else:
label = child.name
post = Post(role=styles_of_address[self.division_id]['Member'], label=label, division_id=child.id, organization_id=organization._id)
yield post
if not children and parent.attrs['posts_count']:
for i in range(1, int(parent.attrs['posts_count'])): # exclude Mayor
organization.add_post(role=styles_of_address[self.division_id]['Member'], label='{} (seat {})'.format(parent.name, i), division_id=parent.id)
yield organization
示例5: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self):
org = Organization(name="Ferguson City Council",
classification="legislature")
org.add_contact_detail(
type='email',
value='[email protected]'
)
org.add_post(
label="Mayor",
role="Mayor",
division_id=self.division_id
)
WARDS = 3
for ward in range(1, WARDS + 1):
org.add_post(
label="Council Member Ward {}".format(ward),
role="Council Member Ward {}".format(ward),
division_id=self.division_id,
# num_seats=2,
)
yield org
示例6: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self):
organization = Organization(self.name, classification=self.classification)
organization.add_post(role='Mayor', label='Waterloo', division_id=self.division_id)
for ward_number in range(1, 8):
organization.add_post(role='Councillor', label='Ward {}'.format(ward_number))
yield organization
示例7: board_of_aldermen
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def board_of_aldermen(self):
org = Organization(name="St Louis Board of Aldermen",
classification="legislature")
# add a post for each Ward
for ward_num in range(1, self.WARD_COUNT + 1):
org.add_post(label="Ward {} Alderman".format(ward_num),
role="Alderman")
yield org
示例8: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self): # @todo Eliminate once shapefile is found and ocd-division-ids is updated.
organization = Organization(self.name, classification=self.classification)
organization.add_post(role='Maire', label='Mercier', division_id=self.division_id)
for district_number in range(1, 7):
organization.add_post(role='Conseiller', label='District {}'.format(district_number))
yield organization
示例9: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self):
organization = Organization(self.name, classification=self.classification)
organization.add_post(role='Mayor', label=self.division_name, division_id=self.division_id)
for division in Division.get('ocd-division/country:ca/csd:3520005').children('ward'):
if '2018' in division.id:
organization.add_post(role='Councillor', label=division.name, division_id=division.id)
yield organization
示例10: test_org_add_post
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def test_org_add_post():
""" Test that we can hack posts in on the fly'"""
orga = Organization("name", classification="committee")
orga.add_source(url='foo')
orga.validate()
orga.add_post("Human Readable Name", "Chef")
assert orga._related[0].role == "Chef"
assert orga._related[0].label == "Human Readable Name"
示例11: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self):
org = Organization(name="Sacramento City Council", classification="legislature")
org.add_post(label='Mayor of the City of Sacramento',
role='Mayor',
division_id='ocd-division/country:us/state:ca/place:sacramento')
for district in range(1, 9):
org.add_post(label='Sacramento City Council Member, District {}'.format(district),
role='Member',
division_id='ocd-division/country:us/state:ca/place:sacramento/council_district:{}'.format(district))
yield org
示例12: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def get_organizations(self):
org = Organization(name="Miami-Dade County Commission",
classification="legislature")
for x in range(1,14):
org.add_post(label="District {dist} Commissioner".format(dist=x),
role="Commissioner",
division_id=self.division_id)
yield org
mayor = Organization('Office of the Mayor', classification='executive')
yield mayor
mayorPers = Person(name="Carlos A. Giménez",
primary_org='executive',
role='Mayor',
primary_org_name='Office of the Mayor',
start_date=datetime.date(2011, 6, 28))
mayorPers.add_source('Ernie')
yield mayorPers
clerk = Organization('Clerk of Courts', classification='executive')
yield clerk
clerkPers = Person(name="Harvey Ruvin",
primary_org='executive',
role='Clerk',
primary_org_name='Clerk of Courts')
clerkPers.add_source('Ernie')
yield clerkPers
pa = Organization('Office of the Property Appraiser', classification='executive')
yield pa
paPers = Person(name="Pedro J. Garcia",
primary_org='executive',
role='Property Appraiser',
primary_org_name='Office of the Property Appraiser')
paPers.add_source('Ernie')
yield paPers
示例13: scrape
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_post [as 别名]
def scrape(self):
sessions = reversed(self.jurisdiction.legislative_sessions)
committee_term_instances = committees_from_sessions(self, sessions)
committees_by_code = build_lookup_dict(self, data_list=committee_term_instances, index_key='code')
for code, instances in committees_by_code.items():
# TODO: Figure out how to edit city council org.
if code == 'CC':
continue
# When there are no meetings scheduled and was no way to deduce committee code.
if not code:
continue
extras = {'tmmis_decision_body_ids': []}
for i, inst in enumerate(instances):
# TODO: Ensure this survives addition of new term (2017)
# so specific year always creates
canonical_i = 0
if i == canonical_i:
o = Organization(name=inst['name'], classification='committee')
extras.update({'description': inst['info']})
o.add_identifier(inst['code'], scheme=TWO_LETTER_ORG_CODE_SCHEME)
# TODO: Scrape non-councillor members
meeting_id = self.referenceMeetingId(inst['code'], inst['term'])
if meeting_id:
seen_posts = []
membership_url = MEMBERSHIP_URL_TEMPLATE.format(meeting_id)
for councillor in self.councillorMembers(membership_url):
o.add_member(councillor['name'], councillor['role'])
if councillor['role'] not in seen_posts:
o.add_post(
role=councillor['role'],
label=councillor['role'],
# TODO: More specific divisions for some committee?
division_id=self.jurisdiction.division_id,
)
seen_posts.append(councillor['role'])
extras['tmmis_decision_body_ids'].append({inst['term']: inst['decision_body_id']})
o.extras = extras
o.add_source(inst['source_url'])
if instances[canonical_i]['name'] != inst['name']:
# TODO: Add start_date and end_date
o.add_name(inst['name'])
yield o