-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.py
30 lines (23 loc) · 1.1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from os import getenv
from datetime import datetime, timedelta
from portfolio_report.util import handle_env, get_trading_days_close
from portfolio_report.process import PortfolioReport
from apscheduler.schedulers.background import BlockingScheduler
# Handle environment variables:
handle_env()
# Create portfolio report instance:
INPUT_FILEPATH = "data/portfolios_input.xlsx"
RECIPIENT_EMAILS = ["[email protected]"]
reporter = PortfolioReport(INPUT_FILEPATH, finnhub_apikey=getenv("FINNHUB_APIKEY"),
recipient_emails=RECIPIENT_EMAILS)
# Get all trading day close times from now to a year from now:
now = datetime.now().strftime("%Y-%m-%d")
final = (datetime.now() + timedelta(days=365)).strftime("%Y-%m-%d")
closing_times = get_trading_days_close(_from=now, _to=final)
# Setup the task scheduler and set the report task for each closing day:
schedule = BlockingScheduler()
for time in closing_times:
schedule.add_job(reporter.run, 'date', run_date=time.strftime('%Y-%m-%d %H:%M:%S'))
# Start the scheduler to run indefinitely
# TODO: Need to implement error logs
schedule.start()