Add artifact.1/src/artifact_1/cli.py
This commit is contained in:
parent
25a5c9f1fb
commit
da20aa3715
1 changed files with 50 additions and 0 deletions
50
artifact.1/src/artifact_1/cli.py
Normal file
50
artifact.1/src/artifact_1/cli.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
import argparse
|
||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from artifact_1.core import generate_signal_plot
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""CLI entrypoint for the FM Spectrum Walk Analyzer."""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Analyse und Visualisierung von UKW-Signalstärken aus SDR-CSV-Daten."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--input",
|
||||||
|
required=True,
|
||||||
|
help="Pfad zu einer CSV-Datei mit FM-Signaldaten."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
required=False,
|
||||||
|
default="output/signal_plot.png",
|
||||||
|
help="Pfad zur Ausgabedatei für den Plot (Standard: output/signal_plot.png)."
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_path = Path(args.input)
|
||||||
|
output_path = Path(args.output)
|
||||||
|
|
||||||
|
# Input validation: ensure file exists and is a CSV
|
||||||
|
if not input_path.exists() or not input_path.is_file():
|
||||||
|
print(f"Fehler: Die Eingabedatei '{input_path}' wurde nicht gefunden oder ist ungültig.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if input_path.suffix.lower() != ".csv":
|
||||||
|
print("Fehler: Eingabedatei muss im CSV-Format vorliegen.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
fig = generate_signal_plot(str(input_path))
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
fig.savefig(output_path, dpi=150, bbox_inches="tight")
|
||||||
|
print(f"Plot erfolgreich erzeugt: {output_path}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Fehler während der Verarbeitung: {e}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue