Skip to content

Commit

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

import argparse
import re

#
# Args
#
argParser = argparse.ArgumentParser()
argParser.add_argument('--check', dest='check', help='String to check against known good')
argParser = argparse.ArgumentParser(prog="convert.py",
description="Convert street address to latitude/longitude.")

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}<<<")
address = args.address
print(f"You entered an address off >>>{address}<<<")

# Add in town/state if needed
if (not re.search('natick', address)):
address+= ", natick, ma"
print(f"(Added in town) >>>{address}<<<")

# importing geopy library and Nominatim class
# Library to convert addresses
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(args.address)

# printing address
print(getLoc.address)
# Convert address entered
getLoc = loc.geocode(address)

# printing latitude and longitude
# Show information about the address
print(f"Normalized address = {getLoc.address}")
print(f"Latitude = {getLoc.latitude:.6f}")
print(f"Longitude = {getLoc.longitude:.6f}")
15 changes: 14 additions & 1 deletion python/latitude/tests/convert.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ function setup() {



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

@test "Run with basic address 1245 WORCESTER ST natick ma" {
run convert.py '1245 WORCESTER ST natick ma'
assert_output --partial 'Latitude = 42.300226'
assert_output --partial 'Longitude = -71.383479'
}

@test "Check town addition 1245 WORCESTER ST" {
run convert.py '1245 WORCESTER ST'
assert_output --partial 'Added in town'
assert_output --partial 'Latitude = 42.300226'
assert_output --partial 'Longitude = -71.383479'
}

0 comments on commit a0867f6

Please sign in to comment.