-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use socrata connector, auth for ingest/library calls (#1312)
- Loading branch information
1 parent
e2f01fc
commit 31cce05
Showing
8 changed files
with
72 additions
and
69 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
import requests | ||
from typing import Literal | ||
|
||
SOCRATA_USER = os.getenv("SOCRATA_USER") | ||
SOCRATA_PASSWORD = os.getenv("SOCRATA_PASSWORD") | ||
|
||
|
||
def _simple_auth() -> tuple[str, str] | None: | ||
if SOCRATA_USER and SOCRATA_PASSWORD: | ||
return (SOCRATA_USER, SOCRATA_PASSWORD) | ||
else: | ||
return None | ||
|
||
|
||
def _socrata_request( | ||
url, | ||
method: Literal["GET", "PUT", "POST", "PATCH", "DELETE"], | ||
**kwargs, | ||
) -> requests.Response: | ||
"""Request wrapper to add auth, and raise exceptions on error.""" | ||
request_fn = getattr(requests, method.lower()) | ||
resp: requests.Response = request_fn(url, auth=_simple_auth(), **kwargs) | ||
resp.raise_for_status() | ||
return resp |
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
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