Skip to content

Instantly share code, notes, and snippets.

@DailenG
Created May 15, 2023 19:58
Show Gist options
  • Save DailenG/487cab0a9c3d56737dcfc9a955c171c3 to your computer and use it in GitHub Desktop.
Save DailenG/487cab0a9c3d56737dcfc9a955c171c3 to your computer and use it in GitHub Desktop.
Converts WingetUI Config to JSON String, Saves in config directory as JSON string in .json file
## Converted from PowerShell Script using ChatGPT, test prior to usage
import os
import json
# Get the user profile folder
user_profile_folder = os.path.expanduser("~")
# Set the directory path
directory = os.path.join(user_profile_folder, ".wingetui")
# Get a list of files in the directory (excluding files with extensions)
files = [file for file in os.listdir(directory) if not os.path.splitext(file)[1]]
# Create an empty dictionary to store the key-value pairs
data = {}
# Iterate through each file and add its contents to the dictionary
for file in files:
with open(os.path.join(directory, file), "r") as f:
key = os.path.splitext(file)[0]
value = f.read()
if not value:
data[key] = True
else:
data[key] = value
# Create a dictionary with the Config property containing the data dictionary
result = {"Config": data}
# Convert the dictionary to a JSON string
jsonString = json.dumps(result)
# Save the JSON string to a file
with open(os.path.join(directory, "WingetUIConfig.json"), "w") as f:
f.write(jsonString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment