Sorry it took a few days to get back to this. The basic code looks
like the following:
import GeoIP
gi = GeoIP.open("/usr/share/GeoIP/GeoLiteCity.dat",
GeoIP.GEOIP_STANDARD)
ipaddr = cherrypy.request.headers.get("X-Forwarded-For")
gir = gi.record_by_addr(ipaddr)
country = gir['country_code']
region = gir['region']
search = country
if country in ('US', 'CA'):
search = '%s-%s' % (country, region)
if timezones.country_to_timezone.has_key(search):
timezone = models.timezones.country_to_timezone[search]
else:
timezone = DEFAULT_TIMEZONE
In this case, the IP address is extracted from the X-Forwarded-For
header because we're running TG behind Apache - replace this with
whatever source of IP address you have.
This is using the GeoIP free city-level database (http://
www.maxmind.com/app/geolitecity) which is sufficiently accurate for
our purposes. It also relies on a dictionary that maps country codes/
country+state codes to the appropriate timezone code. This is a
pretty long dictionary - email me directly (jason at panopta dot com)
if you'd like a copy.
Again, it's not foolproof, but it's been reasonably accurate for us so
far.
-jason
On Apr 6, 2:00 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Jason....
>
> That would be great. I'd love to see your code.
>
> Thanks
> Sam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---