Functions
參數類型定義範例
def _gpt_parse_images(
image_infos: List[Tuple[str, List[str]]],
prompt_dict: Optional[Dict] = None,
output_dir: str = './',
api_key: Optional[str] = None,
base_url: Optional[str] = None,
model: str = 'gpt-4o',
verbose: bool = False,
gpt_worker: int = 1,
**args
) -> str:
"""
Parse images to markdown content.
"""
Print and Log
def print_f(*msg):
'''print and log!'''
# import datetime for timestamps
import datetime as dt
# convert input arguments to strings for concatenation
message = []
for m in msg:
message.append(str(m))
message = ' '.join(message)
# append to the log file
with open('/tmp/test.log','a') as log:
log.write(f'{dt.datetime.now()} | {message}\n')
# print the message using the copy of the original print function to stdout
print(message)
print_f('Test Message')
Sendmail via SMTP
def send_message(body, subject, to_addr):
import smtplib
from email.message import EmailMessage
smtp_user = "your-smtp-user"
smtp_pass = "your-smtp-pass"
smtp_server = "smtp-relay.your.server"
smtp_port = "587"
msg = EmailMessage()
msg['Subject'] = subject
msg['From'] = smtp_user
msg['To'] = to_addr
msg.set_content(body)
with smtplib.SMTP(smtp_server, smtp_port) as smtp:
smtp.login(smtp_user, smtp_pass)
smtp.send_message(msg)
debug = send_message("This is plain TEXT email", "Test from SMTP", "alang.hsu@gmail.com")
print(debug)