threadr.lostcave.ddnss.de/variable_grabbler.py

30 lines
768 B
Python

#!/usr/bin/python2
print """
Variable Grabbler - version 2.0
-------------------------------"""
# definitions
import os, json, sys
if not len(sys.argv)==3:
print >> sys.stderr, "Error: Exactly two arguments required: \"python variable_grabbler.py <file to be rewritten> <config file>\""
sys.exit(1)
print "Reading config file...",
config = open(sys.argv[2],"r")
parsed = json.loads(config.read().decode("utf-8"))
config.close()
print "Done."
print "Working on file: "+sys.argv[1]
for x in parsed:
print x,
file_in = open(sys.argv[1], "r")
file_content = file_in.read()
file_in.close()
file_out = open(file_path, "w")
file_out.write(file_content.decode('utf-8').replace("%" + x + "%", parsed[x]).encode('utf-8'))
file_out.close()
print "\nDone."