import os print "Starting Merge..." outputTable=r"C:\Path\To\MergedTable.csv" #Change this to the desired location of your output table emailFolder=r"C:\Path\To\TextEmailsFolder" #Change to the folder that contains your text emails toCSV="Lat,Long,Request,EmailAddress\n" for aFile in os.listdir(emailFolder): if aFile==os.path.basename(outputTable): continue #ignore the merged table if it is already existing in the folder print " Working on: "+aFile f=open(emailFolder+"\\"+aFile,"r") txt=f.read() f.close() #Get SERIAL NUMBER: serNum=os.path.splitext(aFile)[0] #Get Email address: email=txt.split("Email--")[1].split("\n")[0] #Get All the GPS Coordinates: latLongsTxt=txt.split("Mapped Lat/Lon--")[1].split("Map Graphic--")[0].strip() latLongsTxt=latLongsTxt.replace('[','').replace(']','') #Prepare text for output table: for i in latLongsTxt.split(","): latLong=i.replace("/",",").strip() if latLong=="": continue #skip null entries (for example if there is an extra comma at the end of the list) toCSV+=latLong+","+serNum+","+email+"\n" #Create CSV if os.path.exists(outputTable): os.remove(outputTable) #Remove file if it exists f=open(outputTable,"a") f.write(toCSV) f.close() print "Merge complete!\nNew table: "+outputTable raw_input("\nPress enter to exit.")
import os import sys print "Starting Merge..." outputTableName="MergedTable.csv" scriptFile=sys.argv[0] scriptName=os.path.basename(scriptFile) homePath=os.path.dirname(scriptFile) toCSV="Lat,Long,Request,EmailAddress\n" for aFile in os.listdir(homePath): if aFile==scriptName: continue #ignore this script file if aFile==outputTableName: continue #ignore the merged table if it is already existing in the folder print " Working on: "+aFile f=open(homePath+"\\"+aFile,"r") txt=f.read() f.close() #Get SERIAL NUMBER: serNum=os.path.splitext(aFile)[0] #Get Email address: email=txt.split("Email--")[1].split("\n")[0] #Get All the GPS Coordinates: latLongsTxt=txt.split("Mapped Lat/Lon--")[1].split("Map Graphic--")[0].strip() latLongsTxt=latLongsTxt.replace('[','').replace(']','') #Prepare text for output table: for i in latLongsTxt.split(","): latLong=i.replace("/",",").strip() if latLong=="": continue #skip null entries (for example if there is an extra comma at the end of the list) toCSV+=latLong+","+serNum+","+email+"\n" #Create CSV if os.path.exists(homePath+"\\"+outputTableName): os.remove(homePath+"\\"+outputTableName) #Remove file if it exists f=open(homePath+"\\"+outputTableName,"a") f.write(toCSV) f.close() print "Merge complete!\nNew table: "+outputTableName raw_input("\nPress enter to exit.")
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.