Skip to content

Commit

Permalink
restructure workflow scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoKle committed Dec 9, 2023
1 parent 0540126 commit 3eefea4
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 56 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/check.py

This file was deleted.

22 changes: 11 additions & 11 deletions .github/workflows/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import sys
from check import dataValid
from formatJsons import format_and_sort_json_files
from consolidateData import consolidateJsons
from createTsBotJson import createTeamspeakStationBotJson
from createScheduleJson import createScheduleJson
from removeRedundant import removeRedundantScheduleEntries
from tasks.verifyData import checkData
from tasks.removeRedundantEntries import removeRedundantScheduleEntries
from tasks.formatting import format_and_sort_json_files
from tasks.consolidateData import consolidateJsons
from tasks.tsBotWorkflow import createTeamspeakStationBotJson
from tasks.scheduleWorkflow import createScheduleJson

try:
combinedFile = "data.json"
OUTPUT_PATH = "data.json"

folders_to_consolidate = ["edgg", "edmm", "eduu", "edww", "edyy", "edxx"]
folders_to_sort = folders_to_consolidate + ["event_schedules"]
dataValid(folders_to_consolidate)
checkData(folders_to_consolidate)

# remove redundant schedule_groups entries
removeRedundantScheduleEntries(folders_to_consolidate)
Expand All @@ -20,13 +20,13 @@
format_and_sort_json_files(folders_to_sort)

# consolidate all source files into one combined file
consolidateJsons(folders_to_consolidate, combinedFile)
consolidateJsons(folders_to_consolidate, OUTPUT_PATH)

# create schedule json
createScheduleJson(combinedFile, "legacy/schedule.json")
createScheduleJson(OUTPUT_PATH, "legacy/schedule.json")

# create legacy jsons
createTeamspeakStationBotJson(combinedFile, "legacy/atc_station_mappings.json")
createTeamspeakStationBotJson(OUTPUT_PATH, "legacy/atc_station_mappings.json")

except Exception as error:
print(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import json


def consolidateJsons(folders, outputFile):
# Initialize an empty list to store combined JSON data
combined_data = []
Expand All @@ -9,10 +10,10 @@ def consolidateJsons(folders, outputFile):
def load_and_append_json_files(folder):
folder_data = []
for filename in os.listdir(folder):
if filename.endswith('.json'):
if filename.endswith(".json"):
file_path = os.path.join(folder, filename)
try:
with open(file_path, 'r') as json_file:
with open(file_path, "r") as json_file:
data = json.load(json_file)
folder_data.extend(data) # Use extend to add items to the list
except json.JSONDecodeError as e:
Expand All @@ -24,10 +25,10 @@ def load_and_append_json_files(folder):
folder_data = load_and_append_json_files(folder)
combined_data.extend(folder_data)

combined_data.sort(key=lambda x: (x['logon']))
combined_data.sort(key=lambda x: (x["logon"]))

# Write the combined JSON data to a single file
with open(outputFile, 'w') as combined_file:
with open(outputFile, "w") as combined_file:
json.dump(combined_data, combined_file, indent=2)

print(f'Combined data from {len(folders)} folders and saved to {outputFile}')
print(f"Combined data from {len(folders)} folders and saved to {outputFile}")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions .github/workflows/tasks/verifyData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import sys, os, json


def checkData(folders):
print("Checking data:\n")
jsonFilesValid = True
scheduleListsValid = True

for folder in folders:
for filename in os.listdir(folder):
if not filename.endswith(".json"):
continue

file_path = os.path.join(folder, filename)

try:
with open(file_path, "r") as file:
json_content = file.read()
data = json.loads(json_content)

for element in data:
if (
not "schedule_minstation" in element
and not "schedule_groups" in element
):
continue

if element.get("schedule_minstation") and not isinstance(
element.get("schedule_minstation"), list
):
scheduleListsValid = False
print(
f"Error in {file_path}: {element.get('logon')} schedule_minstation has to be a list"
)
if element.get("schedule_groups") and not isinstance(
element.get("schedule_groups"), list
):
scheduleListsValid = False
print(
f"Error in {file_path}: {element.get('logon')} schedule_groups has to be a list"
)

except json.JSONDecodeError as e:
print(f"Invalid JSON: {file_path}: {e}")
jsonFilesValid = False

if not jsonFilesValid:
print("Workflow aborted: Jsons are invalid")
sys.exit(100)
if not scheduleListsValid:
print(
"Workflow aborted: schedule_minstation and schedule_groups must be of type list"
)
sys.exit(200)

0 comments on commit 3eefea4

Please sign in to comment.