-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_commandLine.py
27 lines (22 loc) · 992 Bytes
/
main_commandLine.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
27
import sys
from get_distance import calculate_distance
from get_emissions import calculate_emissions
import call_emission
url = "https://distanceto.p.rapidapi.com/get"
# script can be run from the command line using 'python3 main.py <origin> <destination> <mode> <mass>'
origin = sys.argv[1]
destination = sys.argv[2]
mode = sys.argv[3]
# I made mass an optional argument-- if it isn't supplied, it will default to 1kg (the output will
# represent the emissions generated by moving 1kg from origin to destination)
if len(sys.argv) == 5:
mass = sys.argv[4]
else:
mass = 1
#func111 provides origin, dest, mode, mass
if __name__ == '__main__':
# call on helper functions to compute distance between origin and destination and to calculate
# C02 emissions based on mode of transport
dist = calculate_distance(origin, destination)
emissions = calculate_emissions(dist, mode, mass)
print(str(emissions) + 'g of carbon emissions created')