Ejemplo n.º 1
0
    def handle(self, *args, **options):
        """
        Handle call
        """
        from geocurrency.currencies.models import Currency
        from geocurrency.rates.models import Rate
        today = date.today().strftime('%Y-%m-%d')
        try:
            from_date = datetime.strptime(
                options.get('from_date') or today, '%Y-%m-%d')
            to_date = datetime.strptime(
                options.get('to_date') or today, '%Y-%m-%d')
        except ValueError:
            print("invalid dates")
            exit(-1)
        rate_service = options.get('service') or 'forex'

        for currency in Currency.all_currencies():
            self.stdout.write(
                'fetching rates for currency {}.'.format(currency.code))
            Rate.objects.fetch_rates(
                base_currency=currency.code,
                date_obj=from_date,
                to_obj=to_date,
                rate_service=rate_service
            )
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        from geocurrency.currencies.models import Currency
        from geocurrency.rates.models import Rate

        for currency in Currency.all_currencies():
            self.stdout.write('fetching rates for currency {}.'.format(
                currency.code))
            Rate.objects.fetch_rates(base_currency=currency.code)
Ejemplo n.º 3
0
 def validate_base_currency(value):
     """
     Validate base currency
     :param value: Currency
     """
     from geocurrency.currencies.models import Currency
     if not Currency.is_valid(value):
         raise serializers.ValidationError('Invalid currency')
     return value
Ejemplo n.º 4
0
 def validate_target(value: str):
     """
     Validate target currency
     :param value: string
     """
     from geocurrency.currencies.models import Currency
     if not Currency.is_valid(value):
         raise serializers.ValidationError('Invalid currency')
     return value
Ejemplo n.º 5
0
 def validate_currency(value):
     from geocurrency.currencies.models import Currency
     if not Currency.is_valid(value):
         raise serializers.ValidationError('Invalid currency')
     return value