-
Notifications
You must be signed in to change notification settings - Fork 18
Wv scraper #496
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
Open
Ash1R
wants to merge
11
commits into
biglocalnews:main
Choose a base branch
from
Ash1R:wv-scraper
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
Wv scraper #496
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
42a4e08
fixed issue #469 . First commit to this project
Ash1R b83733b
added a scraper for wv for issue #375
Ash1R 3d8312d
Merged in main
Ash1R 568ca53
removing michigan scraper as per request
Ash1R 6e814da
Merged in main
Ash1R 9faca27
Merged in main
Ash1R 17b8455
removed some redundancy
Ash1R de7ea50
remove an unncessary range()
Ash1R 18182b5
Try to patch mypy errors
stucka 280cb56
Editing on Github may have been a bad idea
stucka 920d488
Editing in Github was a terrible idea. Restoring back to Ashir's last…
stucka 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 hidden or 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
This file contains hidden or 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,90 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pdfplumber | ||
|
|
||
| from .. import utils | ||
| from ..cache import Cache | ||
|
|
||
| __authors__ = ["Ash1R"] | ||
| __tags__ = ["html", "pdf"] | ||
| __source__ = { | ||
| "name": "Workforce West Virginia", | ||
| "url": "https://workforcewv.org/public-information/warn-notices/current-warn-notices", | ||
| } | ||
|
|
||
|
|
||
| def scrape( | ||
| data_dir: Path = utils.WARN_DATA_DIR, | ||
| cache_dir: Path = utils.WARN_CACHE_DIR, | ||
| ) -> Path: | ||
| """ | ||
| Scrape data from west virginia workforce site. | ||
|
|
||
| It was a big pdf with all historical data, | ||
| And I used pdfplumber to extract the tables | ||
| And put them into wv.csv | ||
| """ | ||
| cache = Cache(cache_dir) | ||
| headers = [ | ||
| "Company", | ||
| "Address", | ||
| "Contact Information", | ||
| "Region", | ||
| "County", | ||
| "Date", | ||
| "Projected Date", | ||
| "Type", | ||
| "Number Affected", | ||
| ] | ||
| final_data = [headers] | ||
|
|
||
| wv_pdf = cache.download( | ||
| "WV_WARN_Notices_3-1-11_to_3-22-22.", | ||
| "https://workforcewv.org/images/files/PublicInfo/WV_WARN_Notices_3-1-11_to_3-22-22.pdf", | ||
| ) | ||
| with pdfplumber.open(wv_pdf) as pdf: | ||
| for i in pdf.pages: | ||
| tables = i.find_tables() | ||
| for j in tables: | ||
| data = j.extract(x_tolerance=3, y_tolerance=3) | ||
| company = "" | ||
| companydone = False | ||
| row = [] | ||
| for k in range(len(data)): | ||
| if data[k][0] is not None: | ||
| if ( | ||
| (data[k][0].strip() == "Contact Information") | ||
| or (data[k][0].strip() == "Region") | ||
| or (data[k][0].strip() == "County") | ||
| or (data[k][0].strip() == "Date of Notice") | ||
| or (data[k][0].strip() == "Projected Date") | ||
| or (data[k][0].strip() == "Closure/Mass Layoff") | ||
| or (data[k][0].strip() == "Number Affected") | ||
| ): | ||
| row.append(data[k][1].strip()) | ||
|
|
||
| elif data[k][0].strip() == "Address": | ||
| if not companydone: | ||
| row.append(company) | ||
| companydone = True | ||
| row.append(data[k][1].strip()) | ||
|
|
||
| elif data[k][0].strip() == "Company": | ||
| company = company + data[k][1].strip() | ||
|
|
||
| elif ((data[k][0] is None) and (k != 0)) or ( | ||
| data[k][0] == "None" and k != 0 | ||
| ): | ||
| for p in range(1, len(data[k])): | ||
| if data[k][p] is not None: | ||
| company = company + ", " + data[k][p].strip() | ||
|
palewire marked this conversation as resolved.
Outdated
|
||
|
|
||
| final_data.append(row) | ||
|
|
||
| output_csv = data_dir / "wv.csv" | ||
| utils.write_rows_to_csv(output_csv, final_data) | ||
| return output_csv | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| scrape() | ||
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.
Why is it necessary to the
rangein the loop here? Can you not simple do something more likefor row in data?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.
Each company's data is contained in two consecutive rows, with some blank rows in between these company row-pairs. Alternative company names and addresses are stored on the second row. I used range so I can access the second row using an index of k + 1. I did unnecessarily use range later, so I removed that.