mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-21 19:58:17 +00:00
rate 修复API (#20)
This commit is contained in:
parent
0d6191470a
commit
7e14c2232e
@ -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",
|
||||||
|
6
rate.py
6
rate.py
@ -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))
|
||||||
|
Loading…
Reference in New Issue
Block a user