56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
|
|
from _bootstrap import add_src_to_path
|
|
|
|
add_src_to_path()
|
|
|
|
from lhbfx.config import load_config
|
|
from lhbfx.mailer import send_email
|
|
from lhbfx.pdf_export import generate_daily_report_pdf
|
|
from lhbfx.reporting import (
|
|
build_daily_report,
|
|
build_email_body,
|
|
default_report_output_path,
|
|
get_latest_trade_date,
|
|
)
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(description="Generate and optionally send lhbfx daily report")
|
|
parser.add_argument("--trade-date", help="Trade date in YYYY-MM-DD format")
|
|
parser.add_argument("--send", action="store_true", help="Send email after generating report")
|
|
return parser.parse_args()
|
|
|
|
|
|
def main() -> None:
|
|
args = parse_args()
|
|
config = load_config()
|
|
trade_date = args.trade_date or get_latest_trade_date(config)
|
|
if not trade_date:
|
|
raise RuntimeError("No trade date available in database")
|
|
|
|
report = build_daily_report(config=config, trade_date=trade_date)
|
|
pdf_path = default_report_output_path(trade_date)
|
|
generate_daily_report_pdf(report, pdf_path)
|
|
body_text = build_email_body(report)
|
|
|
|
print(f"Generated PDF: {pdf_path}")
|
|
|
|
if args.send:
|
|
if config.mail is None:
|
|
raise RuntimeError("Mail config is missing")
|
|
subject = f"lhbfx 盘后日报 - {trade_date}"
|
|
send_email(
|
|
mail_config=config.mail,
|
|
subject=subject,
|
|
body_text=body_text,
|
|
attachments=[pdf_path],
|
|
)
|
|
print(f"Email sent to: {', '.join(config.mail.recipients)}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|