Verified Commit 22781e9a authored by Elias Häußler's avatar Elias Häußler 🐛

[FEATURE] Add possibility to suppress status message in download script

parent 057d9669
......@@ -112,6 +112,14 @@ The file `data/source.json` contains important information which are being used
| `keys` | Position of keys (headlines) inside the source file (X and Y) | Object with keys `x` and `y` which contain arrays with numbers |
| `data_rows` | Position of first and last data row | Object with keys `first` and `last` as numbers. `last` can be a row number (e.g. `293`) or the difference from the last available row (e.g. `-4`, more flexible)
### Script parameters
You can pass additional arguments when calling the download script. Run `python3 bin/download.py -h` to get an overview.
| Parameter | Description |
| --- | --- |
| `-q`, `--quiet` | Suppresses status messages (error messages will still be displayed) |
### Installing certificates on macOS
If you are working with macOS, you might run into trouble when running the python script. You might get an output like this:
......
......@@ -7,7 +7,7 @@ import os
import sys
import urllib.request
import urllib.error
from argparse import ArgumentParser
CEND: str = '\033[0m'
CYELLOW: str = '\33[33m'
......@@ -42,7 +42,7 @@ def main():
sys.exit(0)
# Print data information
message("Downloading: {} ...", MESSAGE_INFO, info['title'], )
message("Downloading: {} ...", MESSAGE_INFO, info['title'])
# Write contents of downloaded file
dl = download(info['data_url'], source['keys'], source['data_rows'])
......@@ -256,17 +256,17 @@ def get_source() -> object:
}
def message(text: str, state: int, *args: str):
def message(text: str, state: int, *arguments: str):
"""
Print message to console
:param text: The message text
:param state: The message state; can be MESSAGE_INFO, MESSAGE_SUCCESS or MESSAGE_ERROR
:param args: Additional arguments which replace each {} inside the message text
:param arguments: Additional arguments which replace each {} inside the message text
:return:
"""
if not text or state not in [MESSAGE_INFO, MESSAGE_ERROR, MESSAGE_SUCCESS]:
if not text or state not in [MESSAGE_INFO, MESSAGE_ERROR, MESSAGE_SUCCESS] or (args.quiet and state != MESSAGE_ERROR):
return
# Set message prefix and styles
......@@ -287,7 +287,7 @@ def message(text: str, state: int, *args: str):
arg_color = CGREEN
# Show message
print((colors['start'] + prefix + text + colors['end']).format(*[arg_color + arg + CEND for arg in args]))
print((colors['start'] + prefix + text + colors['end']).format(*[arg_color + arg + CEND for arg in arguments]))
def unique(elements: list) -> list:
......@@ -306,4 +306,10 @@ def unique(elements: list) -> list:
# ======================================================================================================================
# Initialize arguments
parser = ArgumentParser()
parser.add_argument('-q', '--quiet', help="Disable output of status messages", action='store_true')
args = parser.parse_args()
# Execute main script
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment