Skip to content

Commit f65c292

Browse files
arguments added to app.py
1 parent ec8f74c commit f65c292

4 files changed

Lines changed: 48 additions & 329 deletions

File tree

src/rules_validation_api/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 🧪 Campaign-config Validation
2+
3+
This Python script is designed to validate a campaign configuration JSON file.
4+
5+
## 🛠 Requirements
6+
7+
- Python 3.13
8+
- `rules_validation_api` must be installed and accessible
9+
- Campaign configuration JSON file to verify
10+
11+
## Steps to verify
12+
13+
- Get to the `rules_validation_api` folder
14+
- Run `python app.py --config_path <path_to_config>`
15+
16+
## Results
17+
18+
- `On success`:
19+
20+
```text
21+
"Valid config" is printed
22+
23+
- `On Failure`:
24+
25+
```text
26+
"Errors" is printed

src/rules_validation_api/app.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
import argparse
12
import json
23
import sys
34
from pathlib import Path
45

56
from rules_validation_api.validators.rules_validator import RulesValidation
67

8+
GREEN = "\033[92m"
9+
RESET = "\033[0m"
10+
YELLOW = "\033[93m"
11+
RED = "\033[91m"
12+
713

814
def main() -> None:
9-
with Path.open(Path("campaign_config.json")) as file:
10-
json_data = json.load(file) # this validates json
11-
RulesValidation(**json_data)
12-
sys.stdout.write("Valid Config\n")
15+
parser = argparse.ArgumentParser(description="Validate campaign configuration.")
16+
parser.add_argument("--config_path", required=True, help="Path to the campaign config JSON file")
17+
args = parser.parse_args()
18+
19+
try:
20+
with Path(args.config_path).open() as file:
21+
json_data = json.load(file)
22+
RulesValidation(**json_data)
23+
sys.stdout.write(f"{GREEN}Valid Config{RESET}\n")
24+
except ValueError as e:
25+
sys.stderr.write(f"{YELLOW}Validation Error:{RESET} {RED}{e}{RESET}\n")
1326

1427

1528
if __name__ == "__main__":

src/rules_validation_api/campaign_config.json

Lines changed: 0 additions & 320 deletions
This file was deleted.

0 commit comments

Comments
 (0)