【发布时间】:2022-10-08 05:22:30
【问题描述】:
我得到了以下文件,并想改用参数。如何在 Python 中传递它们?
import pandas as pd
import mysql.connector
from sqlalchemy import create_engine
from urllib.parse import quote
from io import StringIO
import smtplib, ssl
import mimetypes
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.application import MIMEApplication
from email import encoders
import logging
username = "xxxxx"
password = "yyyyyy"
port = 3306
database = "esxinfo"
engine = create_engine('mysql+mysqlconnector://test:%s@jenkins:3306/esxinfo' % quote('xxxxxx'))
sql = pd.read_sql('SELECT * FROM esx_info', engine)
df = pd.DataFrame(sql)
textStream = StringIO()
df.to_csv(textStream,index=False)
def sendmail():
msg = MIMEMultipart()
my_address ="mygmail@gmail.com"
app_generated_password = "xxxxxxxxxxxx"
msg['Subject'] = "The Email Subject"
msg["From"]= my_address
msg['To'] = "yyyyyyyyyyy
msg.add_header('Content-Type','text/html')
#msg.set_content("This is the body of the email")
#msg.attach(MIMEText(message, 'html'))
textStream = StringIO()
df.to_csv(textStream,index=False)
msg.attach(MIMEApplication(textStream.getvalue(), Name="test.csv"))
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp:
smtp.login(my_address,app_generated_password) #login gmail account
print("sending mail")
smtp.send_message(msg) #send message
print("mail has sent")
sendmail()
说我想通过
my_address ="mygmail@gmail.com"
我如何在不输入代码的情况下做到这一点?我想用 Jenkins 的参数运行它。
【问题讨论】:
-
如果您从 jenkins 运行它,您应该查看命令行参数tutorialspoint.com/python/python_command_line_arguments.htm