-
-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0672 spider chi northwest home equity #966
Open
SubtleHyperbole
wants to merge
6
commits into
City-Bureau:main
Choose a base branch
from
SubtleHyperbole:0672-spider-chi_northwest_home_equity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0620707
Add chi_northwest_home_equity
SubtleHyperbole ad1adeb
Add chi_northwest_home_equity
SubtleHyperbole 3194cba
Add chi_northwest_home_equity
SubtleHyperbole b4533b3
Add chi_northwest_home_equity
SubtleHyperbole 696ae63
Add chi_northwest_home_equity
SubtleHyperbole 008de20
Merge branch 'City-Bureau:main' into 0672-spider-chi_northwest_home_e…
SubtleHyperbole File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import re | ||
from datetime import datetime | ||
|
||
import requests | ||
import scrapy | ||
from city_scrapers_core.constants import NOT_CLASSIFIED | ||
from city_scrapers_core.items import Meeting | ||
from city_scrapers_core.spiders import CityScrapersSpider | ||
|
||
|
||
class ChiNorthwestHomeEquitySpider(CityScrapersSpider): | ||
name = "chi_northwest_home_equity" | ||
agency = "Chicago Northwest Home Equity Assurance Program" | ||
timezone = "America/Chicago" | ||
start_urls = ["https://nwheap.com/category/meet-minutes-and-agendas/"] | ||
|
||
def parse(self, response): | ||
self.location_dict = { | ||
"3022 N. Harlem": "3022 N. Harlem Ave #2S, Chicago, IL 60634", | ||
"3022 N. Harlem Ave. #2S": "3022 N. Harlem Ave #2S, Chicago, IL 60634", | ||
"3022 Harlem Ave. #2S": "3022 Harlem Ave #2S, Chicago, IL 60634", | ||
"3234 N. Central Ave.": "3234 N. Central Ave, Chicago, IL 60634", | ||
"5363 W. Lawrence Ave.": "5363 W. Lawrence Ave, Chicago, IL 60630", | ||
} | ||
self.location_name_dict = { | ||
"3022 N. Harlem": "Northwest Home Equity Main Office", | ||
"3022 N. Harlem Ave #2S": "Northwest Home Equity Main Office", | ||
"3022 Harlem Ave #2S": "Northwest Home Equity Main Office", | ||
"3234 N. Central Ave.": "Northwest Home Equity Assurance Program", | ||
"5363 W. Lawrence Ave": "Jefferson Park Library", | ||
} | ||
# Before we begin, need to collect meeting minutes data -- which is | ||
# contained on multiple iterative pages (/page/2 /page/3 etc) | ||
r = requests.get("https://nwheap.com/category/meet-minutes-and-agendas/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to use |
||
article_response = scrapy.http.HtmlResponse(r.url, body=r.content).xpath( | ||
"//article" | ||
) | ||
pageNum = 1 | ||
article_all_pages = [] | ||
while (r.status_code) == 200: | ||
for article in article_response: | ||
article_all_pages.append(article) | ||
pageNum += 1 | ||
r = requests.get( | ||
"https://nwheap.com/category/meet-minutes-and-agendas/page/" | ||
+ str(pageNum) | ||
+ "/" | ||
) | ||
article_response = scrapy.http.HtmlResponse(r.url, body=r.content).xpath( | ||
"//article" | ||
) | ||
# Now moving onto the main parse of the meetings list | ||
meeting_response = [] | ||
future_meetings = response.xpath("/html/body/div[1]/div[2]/aside[1]/ul/li") | ||
for meet in future_meetings: | ||
if meet.re(r"\d\d/\d\d/\d\d\d\d"): | ||
meeting_response.append(meet) | ||
past_meetings = response.xpath("/html/body/div[1]/div[2]/aside[2]/ul/li") | ||
for meet in past_meetings: | ||
if meet.re(r"\d\d/\d\d/\d\d\d\d"): | ||
meeting_response.append(meet) | ||
for item in meeting_response: | ||
has_related_article_page = False | ||
meeting_date = item.re_first(r"\d\d/\d\d/\d\d\d\d") | ||
for article in article_all_pages: | ||
article_date = article.xpath(".//a/text()")[0].re_first( | ||
r"\S* \d\d?, ?20\d\d" | ||
) | ||
if article_date is None: | ||
continue | ||
date_obj = datetime.strptime(article_date, "%B %d, %Y").date() | ||
if date_obj.strftime("%m/%d/%Y") == meeting_date: | ||
has_related_article_page = True | ||
article_detail = article | ||
details_page_url = article.re_first(r'http[^"]*') | ||
r1 = requests.get(details_page_url) | ||
details_page_response = scrapy.http.HtmlResponse( | ||
r1.url, body=r1.content | ||
) | ||
if not has_related_article_page: | ||
details_page_response = None | ||
article_detail = None | ||
meeting = Meeting( | ||
title=self._parse_title(item), | ||
description=self._parse_description(article_detail), | ||
classification=self._parse_classification(item), | ||
start=self._parse_start(item), | ||
end=self._parse_end(item), | ||
all_day=self._parse_all_day(item), | ||
time_notes=self._parse_time_notes(item), | ||
location=self._parse_location(item), | ||
links=self._parse_links(details_page_response), | ||
source=self._parse_source(response), | ||
) | ||
yield meeting | ||
|
||
def _parse_title(self, item): | ||
return item.xpath(".//a/text()").extract_first() | ||
|
||
def _parse_description(self, item): | ||
if item is None or item.xpath(".//p/text()").extract_first() is None: | ||
return "No Description" | ||
else: | ||
return item.xpath(".//p/text()").extract_first() | ||
|
||
def _parse_classification(self, item): | ||
return NOT_CLASSIFIED | ||
|
||
def _parse_start(self, item): | ||
date_str = item.re_first(r"\d\d/\d\d/\d\d\d\d") | ||
date_obj = datetime.strptime(date_str, "%m/%d/%Y").date() | ||
time_Str = item.re_first(r"\d:\d\d [ap]m") | ||
time_Time = datetime.strptime(time_Str, "%I:%M %p").time() | ||
return datetime.combine(date_obj, time_Time) | ||
|
||
def _parse_end(self, item): | ||
date_str = item.re_first(r"\d\d/\d\d/\d\d\d\d") | ||
date_obj = datetime.strptime(date_str, "%m/%d/%Y").date() | ||
time_Str = item.re(r"\d:\d\d [ap]m")[-1] | ||
time_Time = datetime.strptime(time_Str, "%I:%M %p").time() | ||
return datetime.combine(date_obj, time_Time) | ||
|
||
def _parse_time_notes(self, item): | ||
return "" | ||
|
||
def _parse_all_day(self, item): | ||
return False | ||
|
||
def _parse_location(self, item): | ||
locationRaw = item.re_first(r"<li>\d\d*? \S* \S* \S*? ?</li>") | ||
if locationRaw is None: | ||
return {"name": "", "address": "No Address Found"} | ||
locationAddy = re.sub(r" ?</?li>", "", locationRaw) | ||
if locationAddy in self.location_dict.keys(): | ||
return { | ||
"name": self.location_name_dict[locationAddy], | ||
"address": self.location_dict[locationAddy], | ||
} | ||
else: | ||
return {"name": "", "address": locationAddy} | ||
|
||
def _parse_links(self, details_page): | ||
if details_page is None: | ||
return [{"href": "", "title": ""}] | ||
link_dict_list = details_page.xpath('//div[@class="entry-content"]').xpath( | ||
".//a[@href]" | ||
) | ||
links = [] | ||
dupe_checker = [] | ||
for link_dict in link_dict_list: | ||
href = link_dict.attrib["href"] | ||
filename = re.sub( | ||
"-", | ||
" ", | ||
re.sub(r".pdf|.docx?", "", link_dict.attrib["href"].split("/")[-1]), | ||
).title() | ||
if href not in dupe_checker: | ||
dupe_checker.append(href) | ||
links.append({"href": href, "title": filename}) | ||
return links | ||
|
||
def _parse_source(self, response): | ||
return response.url |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can be set above by
start_urls
instead of each timeparse
is called