pegler / pytzwhere

python library to look up timezone from lat lng offline
Other
146 stars 54 forks source link

`tz_world_shortcuts.json` is missing from setup.py #44

Closed famanson closed 7 years ago

famanson commented 7 years ago

The missing file prevents the dependency from being installed properly.

I believe this is an easy fix

nicerobot commented 7 years ago

tz_world.json was also not installed.

famanson commented 7 years ago

@nicerobot I fixed this in https://github.com/pegler/pytzwhere/commit/934604c5a4dbb56b8db12a5d533cabdfe68396c1, which @pegler has merged the other day. Perhaps give that a try?

linwoodc3 commented 7 years ago

I had the same error today.

Did you push your new code to Pypi so that when people "pip install" tzwhere, they get the new code fix?

I get the json file when I install directly from the github repo master branch.

pip install git+git://github.com/pegler/pytzwhere.git

Get the error of missing json when i install from pypi.

famanson commented 7 years ago

@linwoodc3 yeah I believe it is on pypi, you need to install tzwhere, not pytzwhere from there

https://pypi.python.org/pypi/tzwhere/3.0.1

nicerobot commented 7 years ago

Where are the files supposed to be?

$ pip download --no-cache-dir tzwhere
$ tar zft tzwhere-3.0.1.tar.gz 
tzwhere-3.0.1/
tzwhere-3.0.1/LICENSE
tzwhere-3.0.1/MANIFEST.in
tzwhere-3.0.1/PKG-INFO
tzwhere-3.0.1/README.md
tzwhere-3.0.1/setup.cfg
tzwhere-3.0.1/setup.py
tzwhere-3.0.1/tzwhere/
tzwhere-3.0.1/tzwhere/__init__.py
tzwhere-3.0.1/tzwhere/tzwhere.py
tzwhere-3.0.1/tzwhere.egg-info/
tzwhere-3.0.1/tzwhere.egg-info/dependency_links.txt
tzwhere-3.0.1/tzwhere.egg-info/PKG-INFO
tzwhere-3.0.1/tzwhere.egg-info/requires.txt
tzwhere-3.0.1/tzwhere.egg-info/SOURCES.txt
tzwhere-3.0.1/tzwhere.egg-info/top_level.txt
$ pip install --no-cache-dir --upgrade --force-reinstall tzwhere
Collecting tzwhere                                                      
  Downloading tzwhere-3.0.1.tar.gz                                    
Collecting shapely (from tzwhere)                                            
  Downloading Shapely-1.5.17.post1-cp36-cp36m-macosx_10_6_intel.whl (2.1MB)   
    100% |████████████████████████████████| 2.1MB 1.8MB/s                             
Installing collected packages: shapely, tzwhere                              
  Found existing installation: Shapely 1.5.17.post1                               
    Uninstalling Shapely-1.5.17.post1:                                           
      Successfully uninstalled Shapely-1.5.17.post1                   
  Found existing installation: tzwhere 3.0.1                                         
    Uninstalling tzwhere-3.0.1:                                               
      Successfully uninstalled tzwhere-3.0.1                                             
  Running setup.py install for tzwhere ... done                                
Successfully installed shapely-1.5.17.post1 tzwhere-3.0.1                               
(python3) bash-3.2$ exit                                       
$ cd lib/python3.6/site-packages
$ find tzwhere
tzwhere
tzwhere/__init__.py
tzwhere/__pycache__
tzwhere/__pycache__/__init__.cpython-36.pyc
tzwhere/__pycache__/tzwhere.cpython-36.pyc
tzwhere/tzwhere.py
$ find tzwhere-3.0.1-py3.6.egg-info
tzwhere-3.0.1-py3.6.egg-info
tzwhere-3.0.1-py3.6.egg-info/dependency_links.txt
tzwhere-3.0.1-py3.6.egg-info/installed-files.txt
tzwhere-3.0.1-py3.6.egg-info/PKG-INFO
tzwhere-3.0.1-py3.6.egg-info/requires.txt
tzwhere-3.0.1-py3.6.egg-info/SOURCES.txt
tzwhere-3.0.1-py3.6.egg-info/top_level.txt
linwoodc3 commented 7 years ago

Just tested this again on a fresh install of tzwhere and got the "no json file" error. Not sure what it is but just wanted to pass on.

MaT1g3R commented 7 years ago

Just tested this again on a fresh install of tzwhere and got the "no json file" error. Not sure what it is but just wanted to pass on.

A temporary workaround im using is to extend the tzwhere class and download the json file like this:

import collections
import json
from pathlib import Path

import numpy
from tzwhere.tzwhere import feature_collection_polygons, read_tzworld, tzwhere

WRAP = numpy.asarray
COLLECTION_TYPE = numpy.ndarray
__data_path = Path(__file__).parent.parent.joinpath('data')
DEFAULT_POLYGONS = __data_path.joinpath('tz_world.json')
DEFAULT_SHORTCUTS = __data_path.joinpath('tz_world_shortcuts.json')

class TzWhere(tzwhere):
    def __init__(self, forceTZ=True):
        featureCollection = read_tzworld(str(DEFAULT_POLYGONS))
        pgen = feature_collection_polygons(featureCollection)
        self.timezoneNamesToPolygons = collections.defaultdict(list)
        self.unprepTimezoneNamesToPolygons = collections.defaultdict(list)
        for tzname, poly in pgen:
            self.timezoneNamesToPolygons[tzname].append(poly)
        for tzname, polys in self.timezoneNamesToPolygons.items():
            self.timezoneNamesToPolygons[tzname] = WRAP(polys)

            if forceTZ:
                self.unprepTimezoneNamesToPolygons[tzname] = WRAP(polys)

        with open(str(DEFAULT_SHORTCUTS), 'r') as f:
            self.timezoneLongitudeShortcuts, self.timezoneLatitudeShortcuts = json.load(
                f)

        self.forceTZ = forceTZ
        for tzname in self.timezoneNamesToPolygons:
            # Convert things to tuples to save memory
            for degree in self.timezoneLatitudeShortcuts:
                for tzname in self.timezoneLatitudeShortcuts[degree].keys():
                    self.timezoneLatitudeShortcuts[degree][tzname] = \
                        tuple(self.timezoneLatitudeShortcuts[degree][tzname])

            for degree in self.timezoneLongitudeShortcuts.keys():
                for tzname in self.timezoneLongitudeShortcuts[degree].keys():
                    self.timezoneLongitudeShortcuts[degree][tzname] = \
                        tuple(self.timezoneLongitudeShortcuts[degree][tzname])
        try:
            super().__init__(forceTZ)
        except FileNotFoundError:
            pass
nicholaspoz commented 7 years ago

tz_world.json and tz_world_shortcuts.json are both missing from the package on pip install. You can verify they are missing from the compressed package download on pypl (https://pypi.python.org/pypi/tzwhere)