Last active
August 29, 2015 14:02
-
-
Save Yepoleb/0f3cf56dbd389bbebf5c to your computer and use it in GitHub Desktop.
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
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