rate 修复API (#20)

This commit is contained in:
LTY_CK_TS 2024-03-04 00:44:34 +00:00 committed by GitHub
parent 0d6191470a
commit 7e14c2232e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -82,7 +82,7 @@
},
{
"name": "rate",
"version": "1.411",
"version": "1.412",
"section": "daily",
"maintainer": "fruitymelon",
"size": "3.4 kb",

View File

@ -21,7 +21,7 @@ if config["application_language"] == "en":
"notice": "Data are updated daily, for encrypted currencies we recommend to use the `bc` plugin.",
"warning": "Data are updated daily"}
API = "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies.json"
API = "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies.json"
currencies = []
data = {}
@ -88,12 +88,12 @@ async def rate(context):
if currencies.count(TO) == 0:
await context.edit(f"{TO}{lang_rate['nc']}{', '.join(currencies)}`")
return
endpoint = f"https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/{FROM.lower()}/{TO.lower()}.json"
endpoint = f"https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/{FROM.lower()}.json"
with urllib.request.urlopen(endpoint) as response:
result = response.read()
try:
rate_data = json.loads(result)
await context.edit(
f'`{FROM} : {TO} = {NB} : {round(NB * rate_data[TO.lower()], 4)}`\n\n{lang_rate["warning"]}')
f'`{FROM} : {TO} = {NB} : {round(NB * rate_data[FROM.lower()][TO.lower()], 4)}`\n\n{lang_rate["warning"]}')
except Exception as e:
await context.edit(str(e))