-
Notifications
You must be signed in to change notification settings - Fork 10
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
NextRequest auth #182 Mendo SO #169 #188
Open
stucka
wants to merge
7
commits into
dev
Choose a base branch
from
nextrequest-182
base: dev
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
7 commits
Select commit
Hold shift + click to select a range
3a79928
Initial auth run
stucka 141119c
Extra testing stuff, but at least one fix
stucka ae09115
NextRequest and Mendo SO production
stucka ed29903
Merge branch 'dev' into nextrequest-182
stucka c8d5fd8
Update contributors list
stucka aa754d6
Document auth metadata
stucka 2fcb392
Merge branch 'dev' into nextrequest-182
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 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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
* Ocheze Amuzie ([@ochezems](https://github.com/ochezems)) | ||
* Irene Casado Sánchez ([@irenecasdo](https://github.com/irenecasado)) | ||
* Dilcia Mercedes ([@dilcia19](https://github.com/dilcia19)) | ||
* Lisa Pickoff-White ([@pickoffwhite](https://github.com/pickoffwhite)) | ||
* Gerald Rich ([@newsroomdev](https://github.com/newsroomdev)) | ||
* Jordan Rynning ([@jrynning](https://github.com/jrynning)) | ||
* Tarak Shah ([@tarakc02](https://github.com/tarakc02 )) | ||
* Nauman Sharif ([@naumansharifwork](https://github.com/naumansharifwork)) | ||
* Mike Stucka ([@stucka](https://github.com/stucka)) | ||
* Serdar Tumgoren ([@zstumgoren](https://github.com/zstumgoren)) |
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,71 @@ | ||
import logging | ||
from pathlib import Path | ||
from typing import Dict, List | ||
|
||
from .. import utils | ||
from ..cache import Cache | ||
from ..platforms.nextrequest import auth_nextrequest, process_nextrequest | ||
|
||
# from ..utils import MetadataDict | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Site: | ||
"""Scrape file metadata for the Mendocino County Sheriff's Office. | ||
|
||
Attributes: | ||
name (str): The official name of the agency | ||
""" | ||
|
||
name = "Mendocino County Sheriff" | ||
|
||
def __init__( | ||
self, | ||
data_dir: Path = utils.CLEAN_DATA_DIR, | ||
cache_dir: Path = utils.CLEAN_CACHE_DIR, | ||
): | ||
"""Initialize a new instance. | ||
|
||
Args: | ||
data_dir (Path): The directory where downstream processed files/data will be saved | ||
cache_dir (Path): The directory where files will be cached | ||
""" | ||
self.site_slug = "ca_mendocino_county_sheriff" | ||
self.base_url = "https://mendocinocounty.nextrequest.com" | ||
# Initial disclosure page (aka where they start complying with law) contains list of "detail"/child pages with links to the SB16/SB1421/AB748 videos and files | ||
# along with additional index pages | ||
self.data_dir = data_dir | ||
self.cache_dir = cache_dir | ||
self.subpages_dir = cache_dir / (self.site_slug + "/subpages") | ||
self.cache = Cache(cache_dir) | ||
for localdir in [self.cache_dir, self.data_dir, self.subpages_dir]: | ||
utils.create_directory(localdir) | ||
|
||
def scrape_meta(self, throttle: int = 2) -> Path: | ||
"""Gather metadata on downloadable files (videos, etc.). | ||
|
||
Args: | ||
throttle (int): Number of seconds to wait between requests. Defaults to 0. | ||
|
||
Returns: | ||
Path: Local path of JSON file containing metadata on downloadable files | ||
""" | ||
metadata: List = [] | ||
|
||
for folder in ["22-18", "23-27", "20-30"]: | ||
username = utils.get_credentials(f"MENDOSO{folder}_USER") | ||
password = utils.get_credentials(f"MENDOSO{folder}_PASS") | ||
start_url = f"https://mendocinocounty.nextrequest.com/requests/{folder}" | ||
auth: Dict = auth_nextrequest(self.base_url, username, password) | ||
local_metadata = process_nextrequest( | ||
self.subpages_dir, start_url, force=True, throttle=throttle, auth=auth | ||
) | ||
for i, _entry in enumerate(local_metadata): | ||
local_metadata[i]["auth"] = auth | ||
metadata.extend(local_metadata) | ||
|
||
json_filename = self.data_dir / (self.site_slug + ".json") | ||
self.cache.write_json(json_filename, metadata) | ||
|
||
return json_filename |
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
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
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.
Can you add some more details? Should contribs generate that?