28 lines
874 B
Python
28 lines
874 B
Python
#!/usr/bin/env python3
|
|
"""
|
|
Cron script: fetch daily USD/VND exchange rate via yfinance.
|
|
Run by systemd timer pfm-fxrate.timer at 8AM daily.
|
|
Always force-refreshes regardless of cache.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from app import create_app
|
|
from app.services.fx_service import force_refresh
|
|
|
|
app = create_app()
|
|
|
|
if __name__ == '__main__':
|
|
with app.app_context():
|
|
print('[fx_rate] Fetching fresh USD/VND rate...')
|
|
result = force_refresh()
|
|
if result:
|
|
status = '(stale fallback)' if result.get('is_stale') else ''
|
|
print(f'[fx_rate] 1 USD = ₫{result["rate"]:,.0f} VND '
|
|
f'[{result["source"]}] {result["date"]} {status}')
|
|
else:
|
|
print('[fx_rate] Failed to fetch rate from all sources.')
|
|
sys.exit(1)
|