26 lines
732 B
Python
26 lines
732 B
Python
#!/usr/bin/env python3
|
|
"""
|
|
Cron script: fetch daily USD/VND exchange rate.
|
|
Run by systemd timer pfm-fxrate.timer at 8AM daily.
|
|
"""
|
|
|
|
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 get_today_rate
|
|
|
|
app = create_app()
|
|
|
|
if __name__ == '__main__':
|
|
with app.app_context():
|
|
result = get_today_rate()
|
|
if result:
|
|
status = '(stale)' 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.")
|
|
sys.exit(1)
|