from ip2geotools.databases.commercial import *
from ip2geotools.databases.noncommercial import *
import folium

ip = "147.229.2.90"

nc = {}
c = {}

map = folium.Map(location=[49.2,16.616667])

formatted_string= """
<b>IP: %s</b>
<p>Country: %s</p>
<p>City: %s</p>
<p>Location: %f, %f </p>
"""
filepath = "C:/Users/moro/OneDrive/škola/Studium - Ing/Diplomová práce/DATA/GeoLite2-City.mmdb"

nc[DbIpCity.__name__] = DbIpCity.get(ip)
nc[HostIP.__name__] = HostIP.get(ip)
#nc[Freegeoip.__name__] = Freegeoip.get(ip)
nc[Ipstack.__name__] = Ipstack.get(ip, "2f665a29acba663979529aa5ec84400b")
nc[MaxMindGeoLite2City.__name__] = MaxMindGeoLite2City.get(ip,None,filepath)
nc[Ip2Location.__name__] = Ip2Location.get(ip, None, r"C:\Users\moro\OneDrive\škola\Studium - Ing\Diplomová práce\DATA\IP2LOCATION-LITE-DB5.BIN")

c[DbIpWeb.__name__] = DbIpWeb.get(ip) 
c[MaxMindGeoIp2City.__name__] = MaxMindGeoIp2City.get(ip)
#c[Ip2LocationWeb.__name__] = Ip2LocationWeb.get(ip)
#c[NeustarWeb.__name__] = NeustarWeb.get(ip)
c[GeobytesCityDetails.__name__] = GeobytesCityDetails.get(ip)
c[IpInfo.__name__] = IpInfo.get(ip,"2f665a29acba663979529aa5ec84400b")
#c[SkyhookContextAcceleratorIp.__name__] = SkyhookContextAcceleratorIp.get(ip)
#c[Eurek.__name__] = Eurek.get(ip)

print("noncommercial")
for name, loc in nc.items():
    #folium.Marker([loc.latitude, loc.longitude], 
    #popup=formatted_string % (loc.ip_address, loc.country, loc.city, loc.latitude, loc.longitude), 
    #icon=folium.Icon(color='blue'), tooltip=name).add_to(map)
    print ("%f N, %f E" % (loc.latitude, loc.longitude))

print("commercial")
for name, loc in c.items():
    #folium.Marker([loc.latitude, loc.longitude], 
    #popup=formatted_string % (loc.ip_address, loc.country, loc.city, loc.latitude, loc.longitude), 
    #icon=folium.Icon(color='red'), tooltip=name).add_to(map)
    print ("%f N, %f E" % (loc.latitude, loc.longitude))

folium.LayerControl().add_to(map)

map.save("locations.html")