Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import arcpy, os, smtplib, socket, shutil
- from datetime import datetime
- from email.MIMEMultipart import MIMEMultipart
- from email.MIMEText import MIMEText
- from email.MIMEBase import MIMEBase
- from email import encoders
- from shutil import copytree, ignore_patterns
- try:
- path = arcpy.GetParameterAsText(0)
- szazezer = arcpy.GetParameter(1)
- tbx_path, selected_tool = os.path.split(path) # Split so you have the toolbox and tool name
- tbx = arcpy.ImportToolbox(tbx_path) # import the toolbox
- tool = getattr(tbx, selected_tool) # get the tool by name from the toolbox
- result = tool() # run the tool with all the required parameters
- uzi = arcpy.GetMessages()
- status = result.status # Will be 4 on successful completion
- except Exception as e:
- arcpy.GetMessages(2) # get only the error messages (alternately just use the exception object)
- # valtozok
- hostname = socket.gethostname()
- IP = socket.gethostbyname(hostname)
- tool_subject = str(tool)[10:14]
- maxSeverity = arcpy.GetMaxSeverity()
- messageCount = arcpy.GetMessageCount()
- time = str(datetime.now())[:19]
- fromaddr = "some@email.com"
- toaddr = "anotherone@email.com"
- msg = MIMEMultipart()
- msg['From'] = fromaddr
- msg['To'] = toaddr
- msg['Subject'] = str(result) + " " + tool_subject + " (" + str(szazezer) + ") lefutott: " + str(status) + " " + str(time) + ": " + str(messageCount) + "db uzenet, a legdurvabb: " + str(maxSeverity)
- body = "tematika: " + str(tool)[10:15] + "\n" + "utem: " + str(tool)[13:15] + "\n" + "100e: " + szazezer + "\n" + "computer: " + hostname + "\n" + "IP: " + IP + "\n\n" + uzi
- msg.attach(MIMEText(body, 'plain'))
- # attachement
- filename = r"pontok_tmodel.dbf"
- attachment = open(r"c:\arcGIS_2_email\input_folder\pontok_tmodel.dbf", "rb")
- part = MIMEBase('application', 'octet-stream')
- part.set_payload((attachment).read())
- encoders.encode_base64(part)
- part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
- msg.attach(part)
- # send email
- server = smtplib.SMTP('1.1.1.1', 25)
- server.starttls()
- server.login("username", "password")
- text = msg.as_string()
- server.sendmail(fromaddr, toaddr, text)
- server.quit()
- #play music
- import subprocess
- subprocess.check_output(["cmd", "/c", "start", r"c:\arcGIS_2_email\zene.bat"])
- #backup files
- time2 = str(datetime.now())[:10] + "_" + str(datetime.now())[11:-13] + str(datetime.now())[14:-10]
- source = r"c:\arcGIS_2_email\output_folder"
- backup1 = r"d:\_..._ide"
- backup2 = tool_subject + "_" + time2
- backup = backup1 + "\\" + backup2
- shutil.copytree(source, backup, ignore=ignore_patterns('*.prj', '*.*p*'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement