# Path: services/geolocation_service.py
# def geolocate(**kwargs):
#     try:
#         geo = geocoder.Geocoder('TexasAm', {'apiKey': settings.CONFIG_DICT['api_keys']['texas_am']})
#         geo.lookup(**kwargs)
#         return geo.lat_long()
#     except KeyError:
#         raise
#         # TODO robust error handling


import sunlight
from django.conf import settings
from services.geolocation_service import geolocate


def determine_district(**kwargs):
    try:
        sunlight.config.API_KEY = settings.CONFIG_DICT['api_keys']['sunlight']
    except:
        raise

    if {'latitude', 'longitude'}.issubset(set(kwargs)):

# Path: services/geolocation_service.py
# def geolocate(**kwargs):
#     try:
#         geo = geocoder.Geocoder('TexasAm', {'apiKey': settings.CONFIG_DICT['api_keys']['texas_am']})
#         geo.lookup(**kwargs)
#         return geo.lat_long()
#     except KeyError:
#         raise
#         # TODO robust error handling


# Path: services/determine_district_service.py
import sunlight
from django.conf import settings
from services.geolocation_service import geolocate



def determine_district(**kwargs):
    try:
        sunlight.config.API_KEY = settings.CONFIG_DICT['api_keys']['sunlight']
    except:
        raise

    if {'latitude', 'longitude'}.issubset(set(kwargs)):

        data = sunlight.congress.locate_districts_by_lat_lon(kwargs.get('latitude'), kwargs.get('longitude'))