Ich muss einen Code neu schreiben, der in Linux geschrieben wurde, der verwendet wurde, um einen Ordner auf neue .txt zu überprüfen Dokumente, konvertiert sie dann in ein .pdf und sendet eine E-Mail an den Benutzer, der das Dokument in das neue PDF legt. Ich bin mit dieser Codiersprache nicht sehr vertraut und kenne daher die Schlüsselwörter nicht, die notwendig sind, um den Code zu ändern, damit er in python neu geschrieben wird. Ein paar Worte wurden geändert, um die Identität zu schützen. Entschuldige die Formatierung, zuerst posten. Dies ist der ursprüngliche Code:Erneutes Schreiben eines .txt in .pdf-Codes von einem Linux-Server auf einen Windows Enterprise 2008-Server
#This script checks the shares drive for "letters": txt files containing the contents of a letter to a customer.
#If it finds a letter, it uses a python script to convert that letter to a pdf, and then overlay that pdf on the
oldDir=`pwd`
sPath="/harris/SCRIPTS/regular_reports/txt2pdf"
iPath="/pdrive/letter2pdf/input"
oPath="/sdrive/letter2pdf/output"
processingPath="/harris/SCRIPTS/regular_reports/txt2pdf/processing"
cd "$iPath"
echo "Checking for $iPath/*.txt"
function run {
#Change to the input directory so I can use relative paths
cd "$iPath"
if ls -1 *.txt; then
#Get a list of all *.txt files in the input directory
list=`ls -1 *.txt`
#Loop through all files, processing one at a time
for file in $list; do
cd "$iPath"
#Move the input file to a temporary location for processing
mv ${file} "${processingPath}/"
cd "$processingPath"
echo ${file}
#The new file will be named the same, just with a .pdf extension
newfile=`echo "$file" | sed 's\.txt\.pdf\'`
#The email address to use is the file name (without extension), followed by @example.ca, so remove the extension.
email=`echo "$file" | sed 's|.txt||'`
echo "the new file is $newfile"
#Convert the text file to a PDF
python $sPath/txt2pdf.py $file
#Overlay the text on the letterhead
python $sPath/overlay.py "${file}.pdf" "${newfile}"
echo "[email protected]"
#The name of the file to email:
emailFile=`date '+%Y%m%d%H%M%S'`"Example.pdf"
outputFile="$oPath/`date '+%Y%m%d%H%M%S'`${newfile}"
cp "${newfile}" "$emailFile"
#If it's a new month, a folder will be created to hold the month's outputs
mkdir "$oPath/`date '+%B_%Y'`"
#Copy the file to the output (archival) directory
cp "${newfile}" "$oPath/`date '+%B_%Y'`/`date '+%Y%m%d%H%M%S'`${newfile}"
#Remove the file
rm "${newfile}"
mv "${newfile}" "$oPath/`date '+%Y%m%d%H%M%S'`${newfile}"
#Send the email
echo "Letter is attached." | mutt -e "my_hdr From:Letter2PDF<[email protected]>" -a "$emailFile" -s "Letter" "${email}@veridian.on.ca"
mv "${newfile}" "$oPath/`date '+%Y%m%d%H%M%S'`${newfile}"
#Remove the files we no longer need
rm "$file" "${file}.pdf"
done
else
echo "no valid files"
fi
cd "$oldDir"
}
run
rm $processingPath/*.pdf
Stack Overflow ist nicht wirklich ein Ort, um Leute zu bitten, Ihre Arbeit für Sie zu tun. Hier können Sie spezifische Programmierfragen stellen. Sagen Sie uns, was passiert, wenn Sie diese Datei auf einem Windows-Server ausführen? Welche Fehlermeldungen erhalten Sie? Fragen Sie, wie Sie ein bestimmtes Problem lösen können und Sie erhalten eine hilfreiche Antwort. – aychedee
Ich habe keine Kenntnis von dem Code, in dem es geschrieben wurde, deshalb habe ich den Beitrag gemacht, sieht aus, als würde ich einfach von vorne anfangen. Es tut uns leid. – jhan11
Nichts zu entschuldigen! Es gibt ein bisschen Kunst, um eine Frage über Stapelüberlauf zu stellen. Viel Glück mit Ihrem Projekt. – aychedee