#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0

    Calculating TimeZones


    Hi All

    I am trying to get the time zones for latitude and longitude coordinates but am having a few problems
    The mistakes are probably very basic

    I have a table in a database with around 600 rows. Each row contains a lat long coordinate for somewhere in the world
    I want to feed these co-ordinates into a function and then retrieve the time zone. The aim being to convert events which have a local time stamp within each of these 600 places into UTC time

    I found a piece of code [http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html] which uses the function [https://gist.github.com/pamelafox/2288222]

    When I try to run the code, I get the error geonames is not defined (This is the function previously linked to)
    I have applied for an account with geonames.
    I think I have just saved the function file in the wrong directory or something simple. Can anyone help

    Code:
    #-------------------------------------------------------------------------------
    # Converts latitude longitude into a time zone
    # REF: https://gist.github.com/pamelafox/2288222
    # REF: http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html
    #-------------------------------------------------------------------------------
    
    geonames_client = geonames.GeonamesClient('Username_alpha')
    geonames_result = geonames_client.find_timezone({'lat': 48.871236, 'lng': 2.77928})
    user.timezone = geonames_result['timezoneId']
    Thanks
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    156
    Rep Power
    2
    Very basic question: did you import geonames?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0
    Hi,

    Yes i figured it out
    I wasn't sure where python looks for the py scripts but it looks in the folder lib

    Once the class was placed in the lib folder, the code worked without any issues

    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo