MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / getLoc

Method getLoc

plugins/Sidebar/SidebarPlugin.py:604–630  ·  view source on GitHub ↗
(self, geodb, ip)

Source from the content-addressed store, hash-verified

602 ])
603
604 def getLoc(self, geodb, ip):
605 global loc_cache
606
607 if ip in loc_cache:
608 return loc_cache[ip]
609 else:
610 try:
611 loc_data = geodb.get(ip)
612 except:
613 loc_data = None
614
615 if not loc_data or "location" not in loc_data:
616 loc_cache[ip] = None
617 return None
618
619 loc = {
620 "lat": loc_data["location"]["latitude"],
621 "lon": loc_data["location"]["longitude"],
622 }
623 if "city" in loc_data:
624 loc["city"] = loc_data["city"]["names"]["en"]
625
626 if "country" in loc_data:
627 loc["country"] = loc_data["country"]["names"]["en"]
628
629 loc_cache[ip] = loc
630 return loc
631
632 def getGeoipDb(self):
633 db_name = 'GeoLite2-City.mmdb'

Callers 1

getPeerLocationsMethod · 0.95

Calls 1

getMethod · 0.45

Tested by

no test coverage detected