-
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.
- Loading branch information
1 parent
c1afc9e
commit 5437e83
Showing
15 changed files
with
230 additions
and
84 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,68 @@ | ||
""" | ||
Copyright 2023 binary butterfly GmbH | ||
Use of this source code is governed by an MIT-style license that can be found in the LICENSE.txt. | ||
""" | ||
|
||
import argparse | ||
import sys | ||
from getpass import getpass | ||
from pathlib import Path | ||
|
||
import requests | ||
|
||
DATA_TYPES = { | ||
'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | ||
'csv': 'text/csv', | ||
'xml': 'application/xml', | ||
'json': 'application/json', | ||
} | ||
|
||
PUSH_BASE_URL = 'http://localhost:5000/api/admin/v1/generic-parking-sites' | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
prog='ParkAPI Push Client', | ||
description='This client helps to push static ParkAPI data', | ||
) | ||
parser.add_argument('source_uid') | ||
parser.add_argument('file_path') | ||
args = parser.parse_args() | ||
source_uid: str = args.source_uid | ||
file_path: Path = Path(args.file_path) | ||
|
||
if not file_path.is_file(): | ||
sys.exit('Error: please add a file as second argument.') | ||
|
||
password = getpass(f'Password for source UID {source_uid}: ') | ||
|
||
file_ending = None | ||
for ending in DATA_TYPES: | ||
if file_path.name.endswith(f'.{ending}'): | ||
file_ending = ending | ||
|
||
if file_ending is None: | ||
sys.exit(f'Error: invalid ending. Allowed endings are: {", ".join(DATA_TYPES.keys())}') | ||
|
||
with file_path.open('rb') as file: | ||
file_data = file.read() | ||
|
||
endpoint = f'{PUSH_BASE_URL}/{file_ending}' | ||
requests_response = requests.post( | ||
url=endpoint, | ||
data=file_data, | ||
auth=(source_uid, password), | ||
headers={'Content-Type': DATA_TYPES[file_ending]}, | ||
) | ||
|
||
if requests_response.status_code == 204: | ||
sys.exit('Upload successful.') | ||
|
||
if requests_response.status_code == 401: | ||
sys.exit('Access denied.') | ||
|
||
sys.exit(f'Unknown error with HTTP status code {requests_response.status_code}.') | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,10 +1,3 @@ | ||
pytest~=7.4.2 | ||
pytest-cov~=4.1.0 | ||
pytest~=7.4.3 | ||
black~=23.10.0 | ||
mypy~=1.6.1 | ||
types-Flask-Migrate~=4.0.0.6 | ||
types-PyYAML~=6.0.12.12 | ||
types-requests~=2.31.0.10 | ||
requests-mock~=1.11.0 | ||
mypy-gitlab-code-quality~=1.0.0 | ||
ruff~=0.1.0 | ||
ruff~=0.1.3 |
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
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
Submodule converter
updated
30 files
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.