From 2d107e6234b9eb5cc724125b3b6a5a1e23f23b3a Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Mon, 24 Feb 2020 00:04:25 +0100 Subject: [PATCH] refined output, fixed indentation --- variable_grabbler.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/variable_grabbler.py b/variable_grabbler.py index bf7d78a..ffe039f 100644 --- a/variable_grabbler.py +++ b/variable_grabbler.py @@ -1,7 +1,7 @@ #!/usr/bin/python2 print """ -Variable Grabbler - version 1.4 +Variable Grabbler - version 1.6 -------------------------------""" # definitions @@ -10,24 +10,29 @@ import os, json, fnmatch dir = os.path.dirname(os.path.abspath(__file__)) file_name_pattern = "*.php" -print "Opening config file..." +print "Reading config file...", config = open("variable_grabbler.cfg","r") parsed = json.load(config) config.close() +print "Done." +print "Working on files:" for x in parsed: + print "["+x+"]:" for path, dirs, files in os.walk(dir): - for fname in fnmatch.filter(files, file_name_pattern): - file_path = os.path.join(path, fname) + print path+" >", + for file_name in fnmatch.filter(files, file_name_pattern): + file_path = os.path.join(path, file_name) - print "Working on file: "+file_path + print file_name, - file_in = open(file_path, "r") - file_content = file_in.read() - file_in.close() + file_in = open(file_path, "r") + file_content = file_in.read() + file_in.close() - file_content = file_content.decode('utf-8').replace("%" + x + "%", parsed[x]).encode('utf-8') + file_content = file_content.decode('utf-8').replace("%" + x + "%", parsed[x]).encode('utf-8') - file_out = open(file_path, "w") - file_out.write(file_content) - file_out.close() + file_out = open(file_path, "w") + file_out.write(file_content) + file_out.close() + print ""