-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.py
More file actions
44 lines (38 loc) · 1.61 KB
/
task1.py
File metadata and controls
44 lines (38 loc) · 1.61 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
def address(address):
url = 'https://developer.nrel.gov/api/utility_rates/v3.json'
api_key = '&api_key=zlllkbtTApEZhSsAewdMglmE9kf7lrPP3nnVN75x&format=JSON'
api_url = url + '?address=' + address + api_key
return api_url
def lat_lon(lat, lon):
url = 'https://developer.nrel.gov/api/utility_rates/v3.json'
api_key = '&api_key=zlllkbtTApEZhSsAewdMglmE9kf7lrPP3nnVN75x&format=JSON'
api_url = url + '?lat=' + str(lat) + '&lon=' + str(lon) + api_key
return api_url
def get_all_info_from_api():
answer = input("Would you like to enter an address or lat/lon?[address/lat_lon]")
if answer == 'address':
return address(input("What is your address: "))
else:
print("You can get you lat/lon coordinates from mygeoposition.com")
lat = float(input("Enter your latitude(Enter between -90 and 90): "))
if lat < -90 or lat > 90:
print("ALERT, That number is out of range, please try again")
lat = float(input("Enter your latitude(Enter between -90 and 90): "))
lon = float(input("Enter your longitude(Enter between -180 and 180):"))
if lon < -180 or lon > 180:
print("ALERT, That number is out of range, please try again")
lon = float(input("Enter your longitude(Enter between -180 and 180): "))
return lat_lon(lat, lon)
get_info = get_all_info_from_api()
r = requests.get(get_info)
print(r.text)
def enter_another_address():
print("Would you like to enter another address or lat/lon coordinates?[y/n]")
if input() == 'y' or input() == 'yes':
get_info = get_all_info_from_api()
r = requests.get(get_info)
print(r.text)
else:
print("No problem, come back again anytime!")
enter_another_address()