Skip to content

Instantly share code, notes, and snippets.

@Yepoleb
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yepoleb/0f3cf56dbd389bbebf5c to your computer and use it in GitHub Desktop.
Save Yepoleb/0f3cf56dbd389bbebf5c to your computer and use it in GitHub Desktop.
import os.path
import yaml
import string
import math
oldfiles = "newfiles/"
newfiles = "homefix/"
allowedchars = string.ascii_letters+string.digits+"_"
for filename in os.listdir(oldfiles):
oldpath = os.path.join(oldfiles, filename)
newpath = os.path.join(newfiles, filename)
f = open(oldpath, "r")
doc = yaml.load(f.read())
f.close()
if "homes" in doc:
newhomes = {}
for homename, prop in doc["homes"].items():
newname = homename
for c in newname:
if c not in allowedchars:
newname = newname.replace(c, "_")
print("Replaced", c, "in", homename, "in file", filename)
print(newname)
newhomes[newname.lower()] = prop
doc["homes"] = newhomes
login = doc["timestamps"]["login"]
logout = doc["timestamps"]["logout"]
newlogin = int(login*10**(9-math.floor(math.log10(login))))
newlogout = int(logout*10**(12-math.floor(math.log10(logout))))
doc["timestamps"]["login"] = newlogin
doc["timestamps"]["logout"] = newlogout
f = open(newpath, "w")
yaml.dump(doc, f, default_flow_style=False)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment