本文整理汇总了Python中pupa.scrape.Bill.extras["locations"]方法的典型用法代码示例。如果您正苦于以下问题:Python Bill.extras["locations"]方法的具体用法?Python Bill.extras["locations"]怎么用?Python Bill.extras["locations"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pupa.scrape.Bill
的用法示例。
在下文中一共展示了Bill.extras["locations"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scrape_events_range
# 需要导入模块: from pupa.scrape import Bill [as 别名]
# 或者: from pupa.scrape.Bill import extras["locations"] [as 别名]
def scrape_events_range(self, start_date, end_date):
def daterange(start_date, end_date):
number_of_days = int((end_date - start_date).days)
for n in range(number_of_days):
yield start_date + dt.timedelta(n)
for date in daterange(start_date, end_date):
calendar_day_url = CALENDAR_DAY_TEMPLATE.format(date.year, date.month - 1, date.day)
events = self.extract_events_by_url(calendar_day_url)
for event in events:
tz = pytz.timezone("America/Toronto")
time = dt.datetime.strptime(event["time"], "%I:%M %p")
start = tz.localize(date.replace(hour=time.hour, minute=time.minute, second=0, microsecond=0))
org_name = event["meeting"]
e = Event(
name=org_name,
start_time=start,
timezone=tz.zone,
location_name=event["location"],
status=STATUS_DICT.get(event["meeting_status"]),
)
e.extras = {"meeting_number": event["no"], "tmmis_meeting_id": event["meeting_id"]}
e.add_source(calendar_day_url)
e.add_participant(name=org_name, type="organization")
def is_agenda_available(event):
return event["publishing_status"] in ["Agenda Published", "Minutes Published"]
def is_council(event):
return True if event["meeting"] == self.jurisdiction.name else False
if is_agenda_available(event):
agenda_url_template = (
AGENDA_FULL_COUNCIL_TEMPLATE if is_council(event) else AGENDA_FULL_STANDARD_TEMPLATE
)
agenda_url = agenda_url_template.format(event["meeting_id"])
full_identifiers = list(self.full_identifiers(event["meeting_id"], is_council(event)))
event_map_url_template = (
"http://app.toronto.ca/tmmis/getAddressList.do?function=getMeetingAddressList&meetingId={}"
)
event_map_url = event_map_url_template.format(event["meeting_id"])
addresses_d = self.addressesByAgendaId(event_map_url)
e.add_source(agenda_url)
agenda_items = self.agenda_from_url(agenda_url)
for i, item in enumerate(agenda_items):
a = e.add_agenda_item(item["title"])
a.add_classification(item["type"].lower())
a["order"] = str(i)
def normalize_wards(raw):
if not raw:
raw = "All"
if raw == "All":
return raw.lower()
else:
return raw.split(", ")
wards = normalize_wards(item["wards"])
identifier_regex = re.compile(r"^[0-9]{4}\.([A-Z]{2}[0-9]+\.[0-9]+)$")
[full_identifier] = [
id for id in full_identifiers if identifier_regex.match(id).group(1) == item["identifier"]
]
a.add_bill(full_identifier)
if full_identifier not in self.seen_agenda_items:
b = Bill(
# TODO: Fix this hardcode
legislative_session="2014-2018",
identifier=full_identifier,
title=item["title"],
from_organization={"name": self.jurisdiction.name},
)
b.add_source(agenda_url)
b.add_document_link(
note="canonical",
media_type="text/html",
url=AGENDA_ITEM_TEMPLATE.format(full_identifier),
)
b.extras["wards"] = wards
addresses = addresses_d.get(full_identifier)
if addresses:
b.extras["locations"] = []
for address in addresses:
location = {"address": {"full_address": address}}
b.extras["locations"].append(location)
self.seen_agenda_items.append(full_identifier)
yield b
yield e