本文整理汇总了Python中pupa.scrape.Organization.add_contact_detail方法的典型用法代码示例。如果您正苦于以下问题:Python Organization.add_contact_detail方法的具体用法?Python Organization.add_contact_detail怎么用?Python Organization.add_contact_detail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pupa.scrape.Organization
的用法示例。
在下文中一共展示了Organization.add_contact_detail方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_contact_detail [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
示例2: test_full_organization
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_contact_detail [as 别名]
def test_full_organization():
org = ScrapeOrganization('United Nations', classification='international')
org.add_identifier('un')
org.add_name('UN', start_date='1945')
org.add_contact_detail(type='phone', value='555-555-1234', note='this is fake')
org.add_link('http://example.com/link')
org.add_source('http://example.com/source')
# import org
od = org.as_dict()
OrganizationImporter('jurisdiction-id').import_data([od])
# get person from db and assert it imported correctly
o = Organization.objects.get()
assert 'ocd-organization' in o.id
assert o.name == org.name
assert o.identifiers.all()[0].identifier == 'un'
assert o.identifiers.all()[0].scheme == ''
assert o.other_names.all()[0].name == 'UN'
assert o.other_names.all()[0].start_date == '1945'
assert o.contact_details.all()[0].type == 'phone'
assert o.contact_details.all()[0].value == '555-555-1234'
assert o.contact_details.all()[0].note == 'this is fake'
assert o.links.all()[0].url == 'http://example.com/link'
assert o.sources.all()[0].url == 'http://example.com/source'
示例3: categorize_data
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_contact_detail [as 别名]
def categorize_data(self, csv_data):
return_objs = []
Contribution = namedtuple('Contribution', self.csv_header_row.replace(' ', '_'))
for line in csv_data.split('\n'): # explicity defining delimiter because otherwise fails in case of single line
if not line:
continue
# cur_obj will be the person or organization that made the contribution
cur_obj = None
contribution = Contribution(*line.split(','))
if contribution.Contributor_Type in self.business_contribution_types:
cur_obj = Organization(contribution.Contributor_Name)
elif contribution.Contributor_Type in self.individual_contribution_types:
cur_obj = Person(contribution.Contributor_Name)
elif contribution.Contributor_Type == 'Unknown/Anonymous':
if contribution.Contributor_Name: #ignoring un-named contributors
#these look like catch-all business contributions
cur_obj = Organization(contribution.Contributor_Name)
if cur_obj:
#we don't set cur_obj in the event that there was an
#anonymous/unknown contribution without a Contribution_Name
#so we need to check that it exists before adding to it
cur_obj.add_source(url=self.search_url)
cur_obj.source_identified = True
if contribution.Contributor_Address:
cur_obj.add_contact_detail(type='address', value=contribution.Contributor_Address)
if contribution.Employer_Name:
cur_obj.extras['Employer'] = contribution.Employer_Name
if contribution.Employer_Occupation:
cur_obj.extras['Occupation'] = contribution.Employer_Occupation
#recipiant_obj is the organization that received the contribution
recipiant_obj = Organization(contribution.Receiving_Committee)
recipiant_obj.extras['Office'] = contribution.Office
recipiant_obj.extras['Filing Period'] = contribution.Filing_Period
recipiant_obj.extras['Fundtype'] = contribution.Fundtype
#transaction is the event linking the donor and recipiant
transaction = Event('Contribution', contribution.Contribution_Date, 'EST', 'Maryland') #EST and Maryland b/c MD
transaction.extras['Contribution Amount'] = contribution.Contribution_Amount
transaction.extras['Contribution Type'] = contribution.Contribution_Type
transaction.add_source(url=self.search_url)
#transaction.source_identified = True
transaction.participants.append(cur_obj.as_dict())
transaction.participants.append(recipiant_obj.as_dict())
yield (cur_obj, recipiant_obj, transaction)
else:
yield []
示例4: categorize_data
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_contact_detail [as 别名]
def categorize_data(self, csv_data):
#Is there a better place to define this?
return_objs = []
Contribution = namedtuple('Contribution', self.csv_header_row.replace(' ', '_'))
for line in csv_data.split('\n'): # explicity defining delimiter because otherwise fails in case of single line
if not line:
continue
cur_obj = None
try:
contribution = Contribution(*line.split(','))
except Exception as e:
import pdb; pdb.set_trace()
if contribution.Contributor_Type in self.business_contribution_types:
cur_obj = Organization(contribution.Contributor_Name)
elif contribution.Contributor_Type in self.individual_contribution_types:
cur_obj = Person(contribution.Contributor_Name)
elif contribution.Contributor_Type == 'Unknown/Anonymous':
if contribution.Contributor_Name: #ignoring un-named contributors
#these look like catch-all business contributions
cur_obj = Organization(contribution.Contributor_Name)
if cur_obj:
cur_obj.add_source(url=self.search_url)
cur_obj.source_identified = True
if contribution.Contributor_Address:
cur_obj.add_contact_detail(type='address', value=contribution.Contributor_Address)
if contribution.Employer_Name:
cur_obj.extras['Employer'] = contribution.Employer_Name
if contribution.Employer_Occupation:
cur_obj.extras['Occupation'] = contribution.Employer_Occupation
recipiant_obj = Organization(contribution.Receiving_Committee)
recipiant_obj.extras['Office'] = contribution.Office
recipiant_obj.extras['Filing Period'] = contribution.Filing_Period
recipiant_obj.extras['Fundtype'] = contribution.Fundtype
transaction = Event('Contribution', contribution.Contribution_Date, 'EST', 'Maryland') #EST and Maryland b/c MD
transaction.extras['Contribution Amount'] = contribution.Contribution_Amount
transaction.extras['Contribution Type'] = contribution.Contribution_Type
transaction.add_source(url=self.search_url)
#transaction.source_identified = True
transaction.participants.append(cur_obj.as_dict())
transaction.participants.append(recipiant_obj.as_dict())
yield (cur_obj, recipiant_obj, transaction)
else:
yield []
示例5: scrape_committees
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_contact_detail [as 别名]
def scrape_committees(self, repos):
for repo in repos:
source = "https://raw.githubusercontent.com/unitedstates/congress-legislators/master/{0}".format(repo)
committees = self.fetch_yaml(source)
for committee in committees:
org = Organization(committee["name"], classification="committee")
org.add_source(source)
for key in committee.keys() & {"url", "rss_url"}:
org.add_link(committee[key])
for key in committee.keys() & {"phone", "address"}:
org.add_contact_detail(
type="voice", value=committee[key]
) if key == "phone" else org.add_contact_detail(type=key, value=committee[key])
for key in committee.keys() & {"senate_committee_id", "house_committee_id", "thomas_id"}:
org.add_identifier(committee[key], scheme=key)
if "subcommittees" in committee:
for subcommittee in committee["subcommittees"]:
sub_org = Organization(subcommittee["name"], classification="committee", parent_id=org._id)
sub_org.add_identifier(subcommittee["thomas_id"], scheme="thomas")
sub_org.add_source(source)
for key in subcommittee.keys() & {"phone", "address"}:
sub_org.add_contact_detail(
type="voice", value=committee[key]
) if key == "phone" else sub_org.add_contact_detail(type=key, value=committee[key])
yield sub_org
yield org
示例6: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_contact_detail [as 别名]
def get_organizations(self):
secretary_of_the_commonwealth = Organization(
name="Office of the Secretary of the Commonwealth, Commonwealth of Virginia",
classification="office"
)
secretary_of_the_commonwealth.add_contact_detail(
type="voice",
value="804-786-2441"
)
secretary_of_the_commonwealth.add_contact_detail(
type="address",
value="1111 East Broad Street, 4th Floor, Richmond, Virginia 23219"
)
secretary_of_the_commonwealth.add_link(
url="https://commonwealth.virginia.gov/",
note="Home page"
)
self._secretary_of_the_commonwealth = secretary_of_the_commonwealth
yield secretary_of_the_commonwealth
示例7: scrape_committees
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_contact_detail [as 别名]
def scrape_committees(self, chamber):
url = _COMMITTEE_URL % _CHAMBERS[chamber]
page = self.get(url, verify=False).text
html = lxml.html.fromstring(page)
table = html.xpath('body/section[2]/div/div/div/section[2]/div[2]/div/div/div/div')[1:]
for row in table:
# committee name, description, hours of operation,
# secretary and office_phone
text = list(row[0].xpath('div')[0].itertext())
attributes = [list(value.replace(u'\xa0', ' ')
.replace('Secretary:', '').encode('ascii', 'ignore')
for value in text
if 'Email:' not in value and value != '\n' and 'Phone:' not in value)]
for i in range(len(attributes[0])):
if 'Room' in str(attributes[0][i]):
attributes[0][i] = str(attributes[0][i]).split('Room')[0].replace(', ', ' ')
org = Organization(chamber=chamber, classification="committee",
name=str(attributes[0][0].decode()))
if len(attributes[0]) > 5:
org.add_contact_detail(type='email', value=str(attributes[0][4].decode()),
note='District Office')
org.add_contact_detail(type='voice', value=str(attributes[0][5].decode()),
note='District Office')
else:
org.add_contact_detail(type='email', value=str(attributes[0][3].decode()),
note='District Office')
org.add_contact_detail(type='voice', value=str(attributes[0][4].decode()),
note='District Office')
org.add_source(url)
# membership
for td in row[1].xpath('div'):
td_text = list(td.itertext())
members = list(value
for value in td_text
if value != ' ' and value != '\n' and value != ',')
role = "member"
for member in members:
if (member in ['Chair', 'Vice Chair']):
role = member.lower()
continue
else:
org.add_member(member.strip(), role=role)
role = "member"
yield org
示例8: transform_parse
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_contact_detail [as 别名]
#.........这里部分代码省略.........
parsed_form['registrant']['registrant_state'],
parsed_form['registrant']['registrant_zip'],
parsed_form['registrant']['registrant_country']]
if len(p) > 0]).strip(),
},
{
"type": "voice",
"note": "contact phone",
"value": parsed_form['registrant']['registrant_contact_phone'],
},
{
"type": "email",
"note": "contact email",
"value": parsed_form['registrant']['registrant_contact_email'],
},
]
registrant_contact_ppb = {
"type": "address",
"note": "principal place of business",
"value": '; '.join([
p for p in [
parsed_form['registrant']['registrant_ppb_city'],
parsed_form['registrant']['registrant_ppb_state'],
parsed_form['registrant']['registrant_ppb_zip'],
parsed_form['registrant']['registrant_ppb_country']]
if len(p) > 0]).strip(),
}
if registrant_contact_ppb["value"]:
registrant_contact_details.append(registrant_contact_ppb)
for cd in registrant_contact_details:
_registrant.add_contact_detail(**cd)
_registrant.extras = {
"contact_details_structured": [
{
"type": "address",
"note": "contact address",
"parts": [
{
"note": "address_one",
"value": parsed_form['registrant'][
'registrant_address_one'],
},
{
"note": "address_two",
"value": parsed_form['registrant'][
'registrant_address_two'],
},
{
"note": "city",
"value": parsed_form['registrant'][
'registrant_city'],
},
{
"note": "state",
"value": parsed_form['registrant'][
'registrant_state'],
},
{
"note": "zip",
"value": parsed_form['registrant'][
'registrant_zip'],
},
示例9: get_organizations
# 需要导入模块: from pupa.scrape import Organization [as 别名]
# 或者: from pupa.scrape.Organization import add_contact_detail [as 别名]
def get_organizations(self):
legislature = Organization("United States Congress",
classification='legislature')
self._legislature = legislature
yield legislature
senate = Organization(
name="United States Senate",
classification='upper',
parent_id=legislature._id,
)
self._senate = senate
yield senate
house = Organization(
name="United States House",
classification='lower',
parent_id=legislature._id,
)
self._house = house
yield house
sopr = Organization(
name="Office of Public Record, US Senate",
classification="office",
parent_id=senate._id,
)
sopr.add_contact_detail(type="voice",
value="202-224-0322")
sopr.add_source(url="http://www.senate.gov/pagelayout/legislative/"
"one_item_and_teasers/opr.htm",
note="Profile page")
sopr.add_source(url="http://www.senate.gov/pagelayout/legislative/"
"g_three_sections_with_teasers/lobbyingdisc.htm"
"#lobbyingdisc=lda",
note="Disclosure Home")
sopr.add_link(url="http://soprweb.senate.gov/index.cfm"
"?event=selectfields",
note="Disclosure Search Portal")
sopr.add_link(url="http://soprweb.senate.gov/",
note="Disclosure Electronic Filing System")
self._sopr = sopr
yield sopr
house_clerk = Organization(
name="Office of the Clerk, US House",
classification="office",
parent_id=house._id,
)
house_clerk.add_contact_detail(type="voice",
value="202-225-7000")
house_clerk.add_source(url="http://clerk.house.gov/",
note="Home page")
self._house_clerk = house_clerk
yield house_clerk
yield legislature