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", "name": "rate",
"version": "1.411", "version": "1.412",
"section": "daily", "section": "daily",
"maintainer": "fruitymelon", "maintainer": "fruitymelon",
"size": "3.4 kb", "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.", "notice": "Data are updated daily, for encrypted currencies we recommend to use the `bc` plugin.",
"warning": "Data are updated daily"} "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 = [] currencies = []
data = {} data = {}
@ -88,12 +88,12 @@ async def rate(context):
if currencies.count(TO) == 0: if currencies.count(TO) == 0:
await context.edit(f"{TO}{lang_rate['nc']}{', '.join(currencies)}`") await context.edit(f"{TO}{lang_rate['nc']}{', '.join(currencies)}`")
return 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: with urllib.request.urlopen(endpoint) as response:
result = response.read() result = response.read()
try: try:
rate_data = json.loads(result) rate_data = json.loads(result)
await context.edit( 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: except Exception as e:
await context.edit(str(e)) await context.edit(str(e))