Coverage for jbank/management/commands/parse_euribor_rates.py: 0%

1 import logging

2 from datetime import timedelta

3 from django.core.management.base import CommandParser

4 from django.utils.timezone import now

5 from jbank.euribor import fetch_latest_euribor_rates

6 from jbank.models import EuriborRate

7 from jutil.command import SafeCommand

8

9 logger = logging.getLogger(__name__)

10

11

12 class Command(SafeCommand):

13 help = "Parses Euribor reference rates published daily by the European Money Markets Institute (EMMI) from suomenpankki.fi feed"

14

15 def add_arguments(self, parser: CommandParser):

16 parser.add_argument("--commit", action="store_true")

17 parser.add_argument("--verbose", action="store_true")

18 parser.add_argument("--delete-older-than-days", type=int)

19

20 def do(self, *args, **kwargs): # pylint: disable=too-many-branches,too-many-locals

21 rates = fetch_latest_euribor_rates(commit=kwargs["commit"], verbose=kwargs["verbose"])

22 for rate in rates:

23 print(f"{rate.record_date.isoformat()},{rate.name},{rate.rate} %")

24 if kwargs["delete_older_than_days"]:

25 old = now() - timedelta(days=kwargs["delete_older_than_days"])

26 EuriborRate.objects.all().filter(created__lt=old).delete()