Last active
January 2, 2016 10:49
-
-
Save matthiasvegh/8292094 to your computer and use it in GitHub Desktop.
Smileys.xml to plist for Adium
This file contains hidden or 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
#!/usr/bin/python | |
import os | |
import xml.etree.ElementTree as ET | |
tree = ET.parse('smileys.xml') | |
root = tree.getroot() | |
smileys = [] | |
for child in root: | |
for child2 in child: | |
for child3 in child2: | |
smileys.append(child3.attrib) | |
print "loaded "+str(len(smileys))+" smileys" | |
plist = ET.Element('plist', {'version': '1.0'}) | |
dict = ET.SubElement(plist, 'dict') | |
version = ET.SubElement(dict, 'key') | |
version.text = 'AdiumSetVersion' | |
iii = ET.SubElement(dict, 'integer') | |
iii.text = "1" | |
emot = ET.SubElement(dict, 'key') | |
emot.text = 'Emoticons' | |
mainDict = ET.SubElement(dict, 'dict') | |
for smiley in smileys: | |
shortcut = smiley['shortcut'] | |
filename = smiley['filename'] | |
currentFName = ET.SubElement(mainDict, 'key') | |
currentFName.text = filename | |
currentStuffDict = ET.SubElement(mainDict, 'dict') | |
currentEq = ET.SubElement(currentStuffDict, 'key') | |
currentEq.text = 'Equivalents' | |
currentArr = ET.SubElement(currentStuffDict, 'array') | |
shC = ET.SubElement(currentArr, 'string') | |
shC.text = shortcut | |
name = ET.SubElement(currentStuffDict, 'key') | |
name.text = 'Name' | |
actualName = ET.SubElement(currentStuffDict, 'string') | |
actualName.text = shortcut | |
output = ET.ElementTree(plist) | |
output.write("Emoticons.plist") | |
with open("Emoticons.plist", "r+") as f: | |
old = f.read() | |
f.seek(0) | |
f.write("""<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">""" + old) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment