Skip to content

Instantly share code, notes, and snippets.

@ColdGrub1384
Last active June 28, 2020 03:55
Show Gist options
  • Save ColdGrub1384/929f59fd3197bc8de360cb781f8a70d1 to your computer and use it in GitHub Desktop.
Save ColdGrub1384/929f59fd3197bc8de360cb781f8a70d1 to your computer and use it in GitHub Desktop.
Import and export Pyto themes
"""
A script for importing and exporting Pyto themes.
"""
from rubicon.objc import ObjCClass, at
from console import clear
import sys
import base64
import sharing
NSUserDefaults = ObjCClass("NSUserDefaults")
NSData = ObjCClass("NSData")
NSString = ObjCClass("NSString")
print("1) Export theme")
print("2) Import theme")
r = input("Select option ")
export = None
if r == "1":
export = True
elif r == "2":
export = False
else:
raise ValueError("Invalid option")
themes = NSUserDefaults.standardUserDefaults.valueForKey("themes")
if export and (themes == None or len(themes) == 0):
print("\nNo custom theme")
sys.exit(1)
elif themes == None:
themes = []
themes = list(themes)
decoded_themes = []
for theme in themes:
decoded_themes.append(base64.b64decode(str(theme.base64EncodedStringWithOptions(0))).decode())
if export:
print("\nSelect a theme\n")
i = 0
for theme in decoded_themes:
i += 1
print(str(i)+") "+theme.split("\n")[0])
selected = int(input("Theme number... "))-1
theme = decoded_themes[selected].replace("\n", "\\n")
sharing.share_items([theme])
else:
theme = input("Paste theme here\n").replace("\\n", "\n")
clear()
theme_data = at(theme).dataUsingEncoding(4)
themes.append(theme_data)
NSUserDefaults.standardUserDefaults.setValue(themes, forKey="themes")
print("Installed theme")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment