Skip to content

Commit

Permalink
Use args
Browse files Browse the repository at this point in the history
  • Loading branch information
nikconwell committed Jan 29, 2024
1 parent a3a53de commit 658cb5f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
23 changes: 20 additions & 3 deletions python/latitude/convert.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
#!/home/nik/github/try/python/latitude/bin/python

import argparse

#
# Args
#
argParser = argparse.ArgumentParser()
argParser.add_argument('--check', dest='check', help='String to check against known good')
argParser.add_argument('--debug', dest='debug', default=False, action='store_true', help='Debug mode for various things')
argParser.add_argument('address')



args = argParser.parse_args()

print(f"You entered an address off >>>{args.address}<<<")


# importing geopy library and Nominatim class
from geopy.geocoders import Nominatim

# calling the Nominatim tool and create Nominatim class
loc = Nominatim(user_agent="Geopy Library")

# entering the location name
getLoc = loc.geocode("172 hartford street natick ma")
getLoc = loc.geocode(args.address)

# printing address
print(getLoc.address)

# printing latitude and longitude
print(f"Latitude = {getLoc.latitude}\n")
print(f"Longitude = {getLoc.longitude}\n")
print(f"Latitude = {getLoc.latitude:.6f}")
print(f"Longitude = {getLoc.longitude:.6f}")
7 changes: 3 additions & 4 deletions python/latitude/tests/convert.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ function setup() {


@test "Make sure it runs" {
run convert.py
assert_output --partial 'Latitude = 42.291409849999994'
assert_output --partial 'Longitude = -71.39804914300714'
run convert.py '172 HARTFORD ST natick ma'
assert_output --partial 'Latitude = 42.291410'
assert_output --partial 'Longitude = -71.398049'
}

0 comments on commit 658cb5f

Please sign in to comment.