Пример #1
0
static PyObject * GeoIP_region_populate_dict(GeoIPRegion * gir) {
  PyObject * retval;
  const char * region_name = NULL;
  retval = PyDict_New();
  GeoIP_SetItemString(retval,"country_code",gir->country_code);
  GeoIP_SetItemString(retval,"region",gir->region);
  if ( gir->country_code[0] ) {
    region_name = GeoIP_region_name_by_code(gir->country_code, gir->region);
  }
  GeoIP_SetItemString(retval,"region_name",region_name);
  GeoIPRegion_delete(gir);
  return retval;
}
Пример #2
0
static PyObject *GeoIP_populate_dict(GeoIP * gi, GeoIPRecord * gir)
{
    PyObject *retval;
    retval = PyDict_New();
    GeoIP_SetItemString(retval, "country_code", gir->country_code);
    GeoIP_SetItemString(retval, "country_code3", gir->country_code3);
    GeoIP_SetItemString(retval, "country_name", gir->country_name);
    GeoIP_SetItemString(retval, "region", gir->region);
    GeoIP_SetItemString(retval, "city", gir->city);
    GeoIP_SetItemString(retval, "postal_code", gir->postal_code);
    GeoIP_SetItemFloat(retval, "latitude", gir->latitude);
    GeoIP_SetItemFloat(retval, "longitude", gir->longitude);
    GeoIP_SetItemString(retval, "region_name",
                        GeoIP_region_name_by_code(gir->country_code,
                                                  gir->region));
    GeoIP_SetItemString(retval, "time_zone",
                        GeoIP_time_zone_by_country_and_region(gir->country_code,
                                                              gir->region));
    if (gi->databaseType != GEOIP_CITY_EDITION_REV0) {
        /*
         * metro_code is a alias for the depreciated dma_code.
         * we use the depreciated gir->dma_code since the CAPI
         * wrapper might be outdated and does not supply metro_code
         */
        GeoIP_SetItemInt(retval, "dma_code", gir->dma_code);
        /* we did __NOT__ use gir->metro_code here, since metro_code is
         * somewhat new */
        GeoIP_SetItemInt(retval, "metro_code", gir->dma_code);
        GeoIP_SetItemInt(retval, "area_code", gir->area_code);
    }

    GeoIPRecord_delete(gir);
    return retval;
}