Created
May 15, 2023 19:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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