获取汇率api使用
1.汇率url
https://www.exchangerate-api.com/docs/supported-currencies
2.调用
class Command(BaseCommand): help = "Sync currency pair and exchange rate" def add_arguments(self, parser): parser.add_argument("--base_currency", type=str, default=["SGD", "HKD", "IDR", "PHP"]) def handle(self, *args, **options): try: base_currencys = options["base_currency"] time.sleep(2) for base_currency in base_currencys: url = f"https://open.er-api.com/v6/latest/{base_currency}" response = requests.get(url=url) if response.ok: result = response.json() data = result["rates"] cache.set(f"{base_currency}_exchange_rates", data) self.stdout.write(self.style.SUCCESS("Successfully sync currency pair and exchange rate")) else: self.stdout.write(self.style.SUCCESS("Failed sync currency pair and exchange rate")) except Exception as e: capture_exception(e)
每天逼着自己写点东西,终有一天会为自己的变化感动的。这是一个潜移默化的过程,每天坚持编编故事,自己不知不觉就会拥有故事人物的特质的。 Explicit is better than implicit.(清楚优于含糊)