@@ -0,0 +1,1750 @@
+# -*- coding: utf-8 -*-%0A%0A%22%22%22Geolocation utils.%22%22%22%0A%0Afrom ..exceptions import RateExceededError%0A%0A%0Adef ip_geoloc(ip, hit_api=True):%0A    %22%22%22%0A    Get IP geolocation.%0A%0A    Args:%0A        ip (str): IP address to use if no data provided.%0A        hit_api (bool): whether to hit api if info not found.%0A%0A    Returns:%0A        str: latitude and longitude, comma-separated.%0A    %22%22%22%0A    from ..logs.models import IPInfoCheck%0A    try:%0A        obj = IPInfoCheck.objects.get(ip_address=ip).ip_info%0A    except IPInfoCheck.DoesNotExist:%0A        if hit_api:%0A            try:%0A                obj = IPInfoCheck.check_ip(ip)%0A            except RateExceededError:%0A                return None%0A        else:%0A            return None%0A    return obj.latitude, obj.longitude%0A%0A%0Adef google_maps_geoloc_link(ip):%0A    %22%22%22%0A    Get a link to google maps pointing on this IP's geolocation.%0A%0A    Args:%0A        ip (str): IP address.%0A%0A    Returns:%0A        str: a link to google maps pointing on this IP's geolocation.%0A    %22%22%22%0A    lat_lon = ip_geoloc(ip)%0A    if lat_lon is not None:%0A        lat, lon = lat_lon%0A        loc = '%25s,%25s' %25 (lat, lon)%0A        return 'https://www.google.com/maps/place/@%25s,17z/' %5C%0A               'data=!3m1!4b1!4m5!3m4!1s0x0:0x0!8m2!3d%25s!4d%25s' %25 (%0A                loc, lat, lon)%0A    return ''%0A%0A%0Adef open_street_map_geoloc_link(ip):%0A    %22%22%22%0A    Get a link to open street map pointing on this IP's geolocation.%0A%0A    Args:%0A        ip (str): IP address.%0A%0A    Returns:%0A        str: a link to open street map pointing on this IP's geolocation.%0A    %22%22%22%0A    lat_lon = ip_geoloc(ip)%0A    if lat_lon is not None:%0A        lat, lon = lat_lon%0A        return 'https://www.openstreetmap.org/search' %5C%0A               '?query=%25s%25%252C%25s#map=7/%25s/%25s' %25 (lat, lon, lat, lon)%0A    return ''%0A

Move geolocation utils into utils.geolocation