-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
26 lines (21 loc) · 978 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from fastapi import FastAPI, HTTPException
from scraper import CurrencyConverterScraper
app = FastAPI()
# Initialisation de l'instance de la classe contenant la methode du scraping
scraper = CurrencyConverterScraper()
# Accueil
@app.get('/')
async def bienvenu():
return f"Bienvenus sur l'API de conversions de devises!"
# API du scraping de conversion des devises
@app.get('/api/convertion_devise')
async def convert(Amont: int, Currency_to_convert: str, Expected_Currency: str):
url = f'https://www.xe.com/fr/currencyconverter/convert/?Amount={Amont}&From={Currency_to_convert}&To={Expected_Currency}'
try:
result = scraper.get_donnee_converties(url)
montant_sortis = result[0]['Montant_sortis']
return f"Resultat en {Expected_Currency}: {montant_sortis}"
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))