Comments (9)
You are importing the module tzwhere and not the class. And I should fix the documentation.
Try something like
from tzwhere import tzwhere
and that should work
from pytzwhere.
@cstich, Thank you so much.
from pytzwhere.
You are welcome :)
from pytzwhere.
By the way, this package is awesome. It took a while for me to find it, but it is exactly what I wanted.
Actually I have a list of city and state or country names and I was trying to identify their current time.
For this purpose, I combined the following four libraries:
from datetime import datetime
from geopy import geocoders
from tzwhere import tzwhere
from pytz import timezone
and the following is an example of my code:
location = "Sackville, Canada"
g = geocoders.GoogleV3()
place, (lat, lng) = g.geocode(location)
tz = tzwhere.tzwhere()
timeZoneObj = tz.tzNameAt(lat, lng)
now_time = datetime.now(timezone(timeZoneObj))
print now_time => 2015-06-26 15:56:37.425000-03:00
Do you know any more efficient way for this purpose?
Thank you again,
Iman
from pytzwhere.
Thank you.
As you are already effectively queering Google, you could just try queering Google for the timezone directly. Have a look at their API and see whether that fits your requirements.
Alternatively there is also a database of cities and their timezone - cities timezone - but I am not sure how complete the list is.
from pytzwhere.
I am actually using Google Geocoder API in order to locate the coordinates of addresses, cities, states, or countries. I think this is important, because these addresses are not formatted appropriately. Some of them may include only country name and others might include city and state. After having the coordinates, it's not efficient for me to use Google Time Zone API, because it doubles the number of requests that my program sends to Google APIs using the same key, which might exceed my quota.
from pytzwhere.
That makes sense and the code you posted looks very reasonable to me.
The only way and from the top of my head to speed up your code would be to parallize it. That should be pretty straightforward.
Edit: Forget what I just said. Sometimes I am too quick to answer :D
There is an obvious bottleneck in your code. If you have more than one point to look-up, do not re-initialize the tzwhere class. I also doubt that you have to initialize the geocoders class every time. Something like this should be quite faster if you have more than one point. This is also now trivial to turn into a function, you feed to a parallel version of map
if you want to go that way.
tz = tzwhere.tzwhere()
g = geocoders.GoogleV3()
locations = ["Sackville, Canada", "London, UK"]
for l in locations:
place, (lat, lng) = g.geocode(l)
timeZoneObj = tz.tzNameAt(lat, lng)
now_time = datetime.now(timezone(timeZoneObj))
print(now_time)
from pytzwhere.
@ImanYZ this comment is just to make sure you see my edited answer from just a second ago. I am not sure how github handles edits and notifications. Better be safe than sorry.
from pytzwhere.
@cstich, Thank you so much for your comment.
from pytzwhere.
Related Issues (20)
- Potentially wrong results returned HOT 17
- Upload 2.3 to pypi? HOT 3
- forceTZ returning unexpected result HOT 5
- all of China should be +0800, but some are showing up as +0600 HOT 5
- tzNameAt bombs with a KeyError on certain latitudes / longitudes HOT 1
- Outdated data HOT 1
- `tz_world_shortcuts.json` is missing from setup.py HOT 8
- package_data are not installed when installing pytzwhere with pip in a venv HOT 5
- tz_world.json.gz does not exits HOT 1
- What happened to tzOffsetAt?
- can't insatll pytzwhere on Win 10
- Add tests to PyPI source tarball? HOT 1
- With latest numpy update, generates an error on initialization HOT 7
- No timezone for Dubai HOT 1
- how to return this format as "GMT +9" or "GMT -5"οΌThx
- VisibleDeprecationWarning HOT 1
- ValueError due to shapely update HOT 5
- ModuleNotFoundError: No module named 'shapely.lib' HOT 2
- Constructor fails with value error
- Is this project still maintained?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytzwhere.