Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
development:python [2023/07/31 17:58] – Zyzonix | development:python [2024/02/27 07:32] (current) – Zyzonix | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Python ===== | + | ====== Python |
===== Snippet list ===== | ===== Snippet list ===== | ||
Line 52: | Line 52: | ||
return mailText | return mailText | ||
- | def sendMail(self, hosts, awakeList, failedList, statusUnknownList): | + | def sendMail(self): |
if EMAILRECEIVER and EMAILSENDER and MAILSERVER and MAILSERVERPORT: | if EMAILRECEIVER and EMAILSENDER and MAILSERVER and MAILSERVERPORT: | ||
import smtplib | import smtplib | ||
Line 65: | Line 65: | ||
msgRoot = MIMEMultipart(" | msgRoot = MIMEMultipart(" | ||
msgRoot[' | msgRoot[' | ||
- | msgRoot[' | + | msgRoot[' |
msgRoot[' | msgRoot[' | ||
- | mailContent = MIMEText(wakeup.buildMail(self)) | + | mailContent = MIMEText(buildMail(self)) |
mailText = MIMEText(mailContent, | mailText = MIMEText(mailContent, | ||
msgRoot.attach(mailText) | msgRoot.attach(mailText) | ||
Line 81: | Line 81: | ||
++++ | ++++ | ||
</ | </ | ||
+ | |||
+ | <panel type=" | ||
+ | ++++ Show/Hide | | ||
+ | <code bash> | ||
+ | # MAILCONFIG | ||
+ | MAILSERVER = "" | ||
+ | MAILSERVERPORT = 587 | ||
+ | MAILUSER = "" | ||
+ | MAILPASSWORD = "" | ||
+ | EMAILRECEIVER = "" | ||
+ | EMAILSENDER = "" | ||
+ | |||
+ | def buildMail(self): | ||
+ | mailText = "" | ||
+ | # build your mail here string by string (mailText += "" | ||
+ | return mailText | ||
+ | |||
+ | def sendMail(self): | ||
+ | if EMAILRECEIVER and MAILUSER and MAILSERVER and MAILSERVERPORT: | ||
+ | import smtplib | ||
+ | from email.mime.multipart import MIMEMultipart | ||
+ | from email.mime.text import MIMEText | ||
+ | from email.header import Header | ||
+ | |||
+ | smtp = smtplib.SMTP(MAILSERVER) | ||
+ | smtp.connect(MAILSERVER, | ||
+ | smtp.ehlo() | ||
+ | smtp.starttls() | ||
+ | smtp.ehlo() | ||
+ | smtp.login(MAILUSER, | ||
+ | # define subject here | ||
+ | subject = "" | ||
+ | msgRoot = MIMEMultipart(" | ||
+ | msgRoot[' | ||
+ | msgRoot[' | ||
+ | msgRoot[' | ||
+ | | ||
+ | | ||
+ | mailContent = buildMail(self) | ||
+ | mailText = MIMEText(mailContent, | ||
+ | | ||
+ | msgRoot.attach(mailText) | ||
+ | try: | ||
+ | smtp.sendmail(MAILUSER, | ||
+ | | ||
+ | except: | ||
+ | print(self, " | ||
+ | print(self, traceback.format_exc()) | ||
+ | | ||
+ | else: | ||
+ | print(self, " | ||
+ | </ | ||
+ | ++++ | ||
+ | </ | ||
+ | |||
+ | ==== Execute Bash command and capture output ==== | ||
+ | //The output will be captured when the command exited.// | ||
+ | <panel type=" | ||
+ | ++++ Show/Hide | | ||
+ | <code bash> | ||
+ | resultEncoded = subprocess.run("/ | ||
+ | result = resultEncoded.stdout.decode()[: | ||
+ | resultErr = resultEncoded.stderr.decode()[: | ||
+ | </ | ||
+ | ++++ | ||
+ | </ | ||
+ | |||
+ | //Sourced from [[https:// | ||
+ | |||
+ | ==== Get current Memory (RAM) information/ | ||
+ | //Using '' | ||
+ | <panel type=" | ||
+ | ++++ Show/Hide | | ||
+ | <code bash> | ||
+ | ++++ | ||
+ | </ | ||
+ | |||
+ | ==== FastAPI/ | ||
+ | === Change Log Format === | ||
+ | Adding the following lines to your '' | ||
+ | <code bash> | ||
+ | log_config = uvicorn.config.LOGGING_CONFIG | ||
+ | log_config[" | ||
+ | uvicorn.run(app, | ||
+ | </ | ||
+ | |||
+ | //Sourced from [[https:// |