Upload files to "/"
This commit is contained in:
41
calcolokm.py
Normal file
41
calcolokm.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from geopy.geocoders import Nominatim
|
||||
from geopy.distance import geodesic
|
||||
from geopy.location import Location
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def locazione(città, nazione="Italia")->Location:
|
||||
location=geolocator.geocode(città)
|
||||
return location
|
||||
geolocator = Nominatim(user_agent="my_app")
|
||||
|
||||
city1 =locazione(input("nome città, regione, nazione di partenza? > "))
|
||||
city2 =locazione(input("nome città, regione, nazione di arrivo? > "))
|
||||
|
||||
distance = geodesic((city1.latitude, city1.longitude), (city2.latitude, city2.longitude)).km
|
||||
print(city1.raw)
|
||||
print(f"\nLa distanza tra:\n{city1}\n e \n{city2}\n è di: {round(distance,2)}, km")
|
||||
# if city1.raw['type'] == 'city':
|
||||
# print("Il nome corrisponde ad una città")
|
||||
# elif city1.raw['type'] == 'administrative':
|
||||
# print("Il nome corrisponde ad una provincia")
|
||||
# elif city1.raw['type'] == 'country':
|
||||
# print("Il nome corrisponde ad una nazione")
|
||||
# else:
|
||||
# print("Il nome non corrisponde ad una città, provincia o nazione")
|
||||
|
||||
import requests
|
||||
|
||||
url = "https://dgsaie.mise.gov.it/prezzi_carburanti_settimanali_export.php?export-type=json&rid=947"
|
||||
|
||||
response = requests.get(url)
|
||||
data = response.json()
|
||||
prezzo_benzina=0
|
||||
for prodotto in data:
|
||||
if prodotto["NOME_PRODOTTO"] == "Benzina" or prodotto["NOME_PRODOTTO"] == "Gasolio auto":
|
||||
if round( float(prodotto["PREZZO"])/1000,2)>prezzo_benzina:
|
||||
prezzo_benzina =round( float(prodotto["PREZZO"])/1000,2)
|
||||
print(f"Il prezzo della {prodotto['NOME_PRODOTTO']} è impostato a: {prezzo_benzina}")
|
||||
|
||||
cm=float(input("imposta il consumo medio km/l del mezzo > "))
|
||||
print(f"il costo del viaggio è di: {round(prezzo_benzina*distance/cm,2)}")
|
||||
Reference in New Issue
Block a user