I am refactoring/moving some code in my init file for better readability and to manage my app's main file. As a result, I'm attempting to import a function from the refactor file into init, but I continue to get this error,
ImportError: cannot import name 'test_state_locations' from 'app.refactor'
Here is how I am importing:
# File: __init__.py
from .refactor import test_state_locations
# File: refactor.py
import requests
from privateinfo import key
from .__init__ import API_BASE_URL
def test_state_locations(state):
url = f'https://covid-19-testing.github.io/locations/{state.lower()}/complete.json'
res = requests.get(url)
testing_data = res.json()
latsLngs = {}
for obj in testing_data:
if obj["physical_address"]:
for o in obj["physical_address"]:
addy = o["address_1"]
city = o["city"]
phone = obj["phones"][0]["number"]
location = f'{addy} {city}'
res2 = requests.get(API_BASE_URL,
params={'key': key, 'location': location})
location_coordinates = res2.json()
lat = location_coordinates["results"][0]["locations"][0]["latLng"]["lat"]
lng = location_coordinates["results"][0]["locations"][0]["latLng"]["lng"]
latsLngs[location] = {'lat': lat, 'lng': lng, 'place': location, 'phone': phone}