Python via shell call: does not work properly; empty result

Hi!
I do have a workflow where I dictate something into Google docs and, export it as a txt file and then I run python script over this txt file to exchange things like 'comma' for "," or "dot" for ".", just it is in German, the exchange. The python script runs successful if I call it from the shell and produces a new txt file in the same directory with the "new" in front.
But somehow it produces an empty result aka a new file with nothin' in it.
Any idea what I am doing wrong?
And btw, any idea how I could add these new file (once they are no longer empty) automatically to a certain scrivener file?
This is how I call it in hazel (except for the ".....") :
and this the python code:
I do have a workflow where I dictate something into Google docs and, export it as a txt file and then I run python script over this txt file to exchange things like 'comma' for "," or "dot" for ".", just it is in German, the exchange. The python script runs successful if I call it from the shell and produces a new txt file in the same directory with the "new" in front.
But somehow it produces an empty result aka a new file with nothin' in it.

Any idea what I am doing wrong?
And btw, any idea how I could add these new file (once they are no longer empty) automatically to a certain scrivener file?
This is how I call it in hazel (except for the ".....") :
- Code: Select all
python3 /Users/ak/....../batchReplaceGoogleDocs.py $1
and this the python code:
- Code: Select all
import sys, os
toRepl = {
"Klammer auf ": "(",
" Klammer zu": ")",
" Punkt": ".",
" Komma": ",",
" Comma": ",",
"neue Zeile": "\n",
"neue Zeilen": "\n",
" Doppelpunkt": ":",
" Ausrufungszeichen": "!",
"Ausrufezeichen": "!",
" comma": ",",
"Stern": "*",
"Bindestrich": "-"
}
filename = sys.argv[1]
newFileName = os.path.join(os.path.split(filename)[0], "new"+os.path.split(filename)[1])
file = open(filename, 'r')
fileNew = open(newFileName, 'w')
for line in file:
for k, v in toRepl.items():
line = line.replace(k, v)
fileNew.write(line)
fileNew.close()
file.close()