Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42373 > unrolled thread

Convert Latitude, Longitude To TimeZone

Started bySteve B <maccten2000@hotmail.com>
First post2013-03-31 16:53 +0200
Last post2013-03-31 11:09 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Convert Latitude, Longitude To TimeZone Steve B <maccten2000@hotmail.com> - 2013-03-31 16:53 +0200
    Re: Convert Latitude, Longitude To TimeZone Roy Smith <roy@panix.com> - 2013-03-31 11:09 -0400

#42373 — Convert Latitude, Longitude To TimeZone

FromSteve B <maccten2000@hotmail.com>
Date2013-03-31 16:53 +0200
SubjectConvert Latitude, Longitude To TimeZone
Message-ID<mailman.4017.1364741666.2939.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

Hi All

 

I'm new to python (4 days J) and was wondering if anyone out there can help
me

 

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

 

#---------------------------------------------------------------------------
----

# 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

[toc] | [next] | [standalone]


#42374

FromRoy Smith <roy@panix.com>
Date2013-03-31 11:09 -0400
Message-ID<roy-0712E3.11091431032013@news.panix.com>
In reply to#42373
In article <mailman.4017.1364741666.2939.python-list@python.org>,
 Steve B <maccten2000@hotmail.com> wrote:

> 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)

The best thing to do when asking questions like this is to copy-paste 
the exact error message you got.  It was probably something like:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'geonames' is not defined

In this example, it's easy enough to figure out what went wrong from 
your description, but in general, giving the exact error helps in the 
diagnosis.

> geonames_client = geonames.GeonamesClient('Username_alpha')
> 
> geonames_result = geonames_client.find_timezone({'lat': 48.871236, 'lng':
> 2.77928})
> 
> user.timezone = geonames_result['timezoneId']

You simply never imported the geonames module.  Somewhere before your 
first line of code, you want to add:

import geonames

This assumes that you've saved the module in a file named "geonames.py".

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web