Skip to content

Commit

Permalink
v1.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jlopez committed Dec 7, 2011
1 parent 33dab8d commit d396c5b
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.2.7 2011-08-23
* Add example test_netspeedcell.py ( Boris Zentner )
1.2.6 2011-06-06
* Add new methods record_by_name_v6 and record_by_addr_v6 to support
GeoIPCityv6 databases. ( Boris Zentner )
1.2.5 2011-05-10
* Remove Confidence and Accuracy Database it is unsued anyway. ( Boris
Zentner )
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Requirements:
Python 2.0 or greater
GeoIP C Library 1.4.7 or greater
GeoIP C Library 1.4.8 or greater

To Install:
python setup.py build
Expand Down
34 changes: 32 additions & 2 deletions py_GeoIP.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,36 @@ static PyObject * GeoIP_populate_dict(GeoIP* gi, GeoIPRecord *gir) {
return retval;
}

static PyObject * GeoIP_record_by_addr_v6_Py(PyObject *self, PyObject *args) {
char * addr;
GeoIPRecord * gir;
GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self;
if (!PyArg_ParseTuple(args, "s", &addr)) {
return NULL;
}
gir = GeoIP_record_by_addr_v6(GeoIP->gi, addr);
if (gir == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
return GeoIP_populate_dict(GeoIP->gi, gir);
}

static PyObject * GeoIP_record_by_name_v6_Py(PyObject *self, PyObject *args) {
char * name;
GeoIPRecord * gir;
GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self;
if (!PyArg_ParseTuple(args, "s", &name)) {
return NULL;
}
gir = GeoIP_record_by_name_v6(GeoIP->gi, name);
if (gir == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
return GeoIP_populate_dict(GeoIP->gi, gir);
}

static PyObject * GeoIP_record_by_addr_Py(PyObject *self, PyObject *args) {
char * addr;
GeoIPRecord * gir;
Expand Down Expand Up @@ -465,8 +495,6 @@ static PyObject * GeoIP_time_zone_by_country_and_region_Py(PyObject *self, PyObj
return Py_BuildValue("s", GeoIP_time_zone_by_country_and_region(country_code, region));
}



static PyMethodDef GeoIP_Object_methods[] = {
{"country_code_by_name", GeoIP_country_code_by_name_Py, 1, "Lookup Country Code By Name"},
{"country_name_by_name", GeoIP_country_name_by_name_Py, 1, "Lookup Country Name By Name"},
Expand All @@ -490,6 +518,8 @@ static PyMethodDef GeoIP_Object_methods[] = {
{"teredo", GeoIP_teredo_Py, 1, "Returns true if teredo is enabled"},
{"id_by_addr", GeoIP_id_by_addr_Py, 1, "Lookup Netspeed By IP Address"},
{"id_by_name", GeoIP_id_by_name_Py, 1, "Lookup Netspeed By Name"},
{"record_by_addr_v6", GeoIP_record_by_addr_v6_Py, 1, "Lookup City Region By IP Address"},
{"record_by_name_v6", GeoIP_record_by_name_v6_Py, 1, "Lookup City Region By Name"},
{NULL, NULL, 0, NULL}
};

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
include_dirs = ['/usr/local/include'])

setup (name = 'GeoIP-Python',
version = '1.2.5',
version = '1.2.7',
description = 'This is a python wrapper to GeoIP',
ext_modules = [module1])
1 change: 1 addition & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
print gi.country_code_by_addr("24.24.24.24")
print gi.country_name_by_addr("24.24.24.24")
print gi.range_by_ip("68.180.206.184")
print GeoIP.lib_version()

28 changes: 28 additions & 0 deletions test_city_acc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python

import GeoIP

gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPCityConfidenceDist.dat",GeoIP.GEOIP_STANDARD)

gir = gi.record_by_name("www.google.com")
#gir = gi.record_by_addr("24.24.24.24")

if gir != None:
print gir['country_code']
print gir['country_code3']
print gir['country_name']
print gir['city']
print gir['region']
print gir['region_name']
print gir['postal_code']
print gir['latitude']
print gir['longitude']
print gir['area_code']
print gir['time_zone']
print gir['metro_code']
print gir['country_conf']
print gir['region_conf']
print gir['city_conf']
print gir['postal_conf']
print gir['accuracy_radius']

35 changes: 35 additions & 0 deletions test_city_charset.py.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/python

import GeoIP

# open the citydatabase. All cities return in iso-8859-1 by default
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPCity.dat",GeoIP.GEOIP_STANDARD)

# lookup a record, where cityname contains chars > 127 ( eg != ascii )
gir = gi.record_by_name("www.osnabrueck.de")

# print the cityname with iso-8859-1 charset
print gir['city'];

# print the cityname transformed to utf8
print unicode(gir['city'], 'iso-8859-1')

# however, at your option GeoIP can return the cityname in utf8
# just put GeoIP into utf8 mode
#
# from now on all records returns in UTF8 until you change the charset again
# Notice, that all previous records return in the previous charset
gi.set_charset(GeoIP.GEOIP_CHARSET_UTF8);

# get a new record, now in utf8
gir2 = gi.record_by_name("www.osnabrueck.de")

# and print it ( should be the same output as on line 2 )
print gir2['city']

## Some more charset examples
# current_charset = gi.charset()
# old_charset = gi.set_charset(GeoIP.GEOIP_CHARSET_ISO_8859_1);



9 changes: 9 additions & 0 deletions test_netspeedcell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/python

import GeoIP

gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPNetSpeedCell.dat",GeoIP.GEOIP_STANDARD)

print gi.org_by_name("yahoo.com")
print gi.org_by_name("www.google.com")
print gi.org_by_addr("24.24.24.24")
18 changes: 18 additions & 0 deletions time_zone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/python

import GeoIP

#1.4.7
#Europe/Berlin
#Europe/Berlin
#None
#America/Los_Angeles
#America/New_York

print GeoIP.lib_version()
print GeoIP.time_zone_by_country_and_region("DE", 'XY')
print GeoIP.time_zone_by_country_and_region("DE", '')
print GeoIP.time_zone_by_country_and_region("US", "")
print GeoIP.time_zone_by_country_and_region("US", "CA")
print GeoIP.time_zone_by_country_and_region("US", "MA")

0 comments on commit d396c5b

Please sign in to comment.