[mirrorbrain-commits] r7936 - in /trunk/mirrordoctor: mb/geoip.py mirrordoctor.py

From: <poeml_at_mirrorbrain.org>
Date: Tue, 22 Dec 2009 00:57:24 -0000
Author: poeml
Date: Tue Dec 22 01:57:23 2009
New Revision: 7936

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=7936&view=rev
Log:
mb new:
- save geographical coordinates in mirror database entries
- mb.geoip.lookup_coordinates() function added which returns geographical
  coordinates from GeoIP, if available

Modified:
    trunk/mirrordoctor/mb/geoip.py
    trunk/mirrordoctor/mirrordoctor.py

Modified: trunk/mirrordoctor/mb/geoip.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mb/geoip.py?rev=7936&r1=7935&r2=7936&view=diff
==============================================================================
--- trunk/mirrordoctor/mb/geoip.py (original)
+++ trunk/mirrordoctor/mb/geoip.py Tue Dec 22 01:57:23 2009
_at_@ -36,6 +36,24 @@
 
     return out.strip().lower()
 
+def lookup_coordinates(addr):
+    try:
+        out = Popen(['geoiplookup_city', '-f', database, addr], stdout=PIPE).communicate()[0]
+    except OSError, e:
+        if e.errno == errno.ENOENT:
+            sys.exit('Error: The geoiplookup_city binary could not be found.\n'
+                     'Make sure to install the geoiplookup_city into a directory contained in $PATH.')
+
+    lat = lng = 0
+    for line in out.splitlines():
+        if line.startswith('Latitude'):
+            lat = float(line.split()[1])
+            continue
+        if line.startswith('Longitude'):
+            lng = float(line.split()[1])
+            continue
+    return lat, lng
+
 
 if __name__ == '__main__':
     import sys

Modified: trunk/mirrordoctor/mirrordoctor.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mirrordoctor.py?rev=7936&r1=7935&r2=7936&view=diff
==============================================================================
--- trunk/mirrordoctor/mirrordoctor.py (original)
+++ trunk/mirrordoctor/mirrordoctor.py Tue Dec 22 01:57:23 2009
_at_@ -172,6 +172,7 @@
             opts.region = mb.geoip.lookup_region_code(host)
         if not opts.country:
             opts.country = mb.geoip.lookup_country_code(host)
+        lat, lng = mb.geoip.lookup_coordinates(host)
 
         r = mb.asn.iplookup(self.conn, host)
         asn, prefix = r.asn, r.prefix
_at_@ -189,6 +190,8 @@
                              country      = opts.country,
                              asn          = asn,
                              prefix       = prefix,
+                             lat          = lat or 0,
+                             lng          = lng or 0,
                              score        = opts.score,
                              enabled      = 0,
                              statusBaseurl = 0,




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Tue Dec 22 2009 - 00:57:25 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT