-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe56880
commit 9ba9671
Showing
6 changed files
with
167 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
import os | ||
import typing as t | ||
|
||
import requests | ||
|
||
from .base import BaseSource | ||
|
||
|
||
class HTTP(BaseSource): | ||
url: str | ||
method: str | ||
request_params: t.Dict[str, t.Any] | ||
|
||
def backup(self, output_dir: str) -> str: | ||
resp = requests.request(self.method, self.url, **self.request_params) | ||
|
||
result = { | ||
"url": self.url, | ||
"timestamp": self.now(), | ||
"result": resp.status_code, | ||
} | ||
is_json = resp.headers.get("Content-Type", "").lower() == "application/json" | ||
if is_json: | ||
result["detail"] = resp.json() | ||
else: | ||
result["msg"] = resp.text | ||
|
||
backup_filename = ( | ||
f"{os.path.join(output_dir, self.backup_filename)}_{self.now()}.json" | ||
) | ||
with open(backup_filename, "w") as f: | ||
json.dump(result, f) | ||
|
||
if resp.ok: | ||
print(f"HTTP call for backup completed successfully.") | ||
else: | ||
print( | ||
f"HTTP call for backup failed with return code {resp.status_code} {resp.text}." | ||
) | ||
|
||
return backup_filename |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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