mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-22 01:57:47 +00:00
rate 修复 API
This commit is contained in:
parent
ea37618ec1
commit
5c3c50a334
@ -35,7 +35,7 @@ class Rate:
|
|||||||
"notice": "数据每日八点更新",
|
"notice": "数据每日八点更新",
|
||||||
"warning": "数据每日八点更新",
|
"warning": "数据每日八点更新",
|
||||||
}
|
}
|
||||||
self.host = "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest"
|
self.host = "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1"
|
||||||
self.api = f"{self.host}/currencies.json"
|
self.api = f"{self.host}/currencies.json"
|
||||||
self.currencies = []
|
self.currencies = []
|
||||||
self.data = {}
|
self.data = {}
|
||||||
@ -52,14 +52,14 @@ class Rate:
|
|||||||
await log(f"Warning: plugin rate failed to refresh rates data. {e}")
|
await log(f"Warning: plugin rate failed to refresh rates data. {e}")
|
||||||
|
|
||||||
async def get_rate(self, from_: str, to_: str, nb: float):
|
async def get_rate(self, from_: str, to_: str, nb: float):
|
||||||
endpoint = f"{self.host}/currencies/{from_.lower()}/{to_.lower()}.json"
|
endpoint = f"{self.host}/currencies/{from_.lower()}.json"
|
||||||
try:
|
try:
|
||||||
req = await client.get(endpoint, follow_redirects=True)
|
req = await client.get(endpoint, follow_redirects=True)
|
||||||
rate__data = req.json()
|
rate__data = req.json()
|
||||||
return (
|
return (
|
||||||
f"`{from_} : {to_} = {nb} : {round(nb * rate__data[to_.lower()], 4)}`"
|
f"`{from_} : {to_} = {nb} : {round(nb * rate__data[from_.lower()][to_.lower()], 4)}`"
|
||||||
f"\n\n"
|
f"\n\n"
|
||||||
f'{self.lang_rate["warning"]}'
|
f'{self.lang_rate["warning"]} - {rate__data["date"]}'
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return str(e)
|
return str(e)
|
||||||
|
Loading…
Reference in New Issue
Block a user