From ee0c162a7c94263abadea1d0575ef23637100860 Mon Sep 17 00:00:00 2001 From: MamdMehrabi Date: Sun, 30 Jun 2024 01:14:21 +0330 Subject: [PATCH] add trx_price --- app/main.py | 1 + app/router/api/trx.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app/router/api/trx.py diff --git a/app/main.py b/app/main.py index 4e5d3395..72cc00f0 100644 --- a/app/main.py +++ b/app/main.py @@ -55,6 +55,7 @@ async def custom_404_handler(request: Request, __): "app.router.api.datetime.router", "app.router.api.dictionary.router", "app.router.api.fake.router", + "app.router.api.trx.router", "app.router.api._github.router", "app.router.api.location.router", "app.router.api.news.router", diff --git a/app/router/api/trx.py b/app/router/api/trx.py new file mode 100644 index 00000000..85d9585d --- /dev/null +++ b/app/router/api/trx.py @@ -0,0 +1,28 @@ +""" +In this api, by using request and crypto site, +we get the current price of Tron currency... +""" + +from fastapi import APIRouter, Response, status + +from requests import post +from bs4 import BeautifulSoup + +router = APIRouter(prefix='/api', tags=["Crypto"]) + +def TRX(): + a = post("https://arzdigital.com/coins/tron/") + soup = BeautifulSoup(a.content , "html.parser") + find = soup.find("div", {"class":"arz-coin-page-data__coin-toman-price"}).text.strip() + return find + +@router.get('/tron', status_code=status.HTTP_200_OK) +@router.post('/tron', status_code=status.HTTP_200_OK) +async def tron(): + price = TRX() + return { + "success": True, + "data": { + "price_tron": price + } + } \ No newline at end of file