Coder Social home page Coder Social logo

[info] Command line about timezonefinder HOT 6 CLOSED

cnaslain avatar cnaslain commented on May 19, 2024
[info] Command line

from timezonefinder.

Comments (6)

jannikmi avatar jannikmi commented on May 19, 2024

Nope. I am not sure what you want to achieve, but of course you could simply write yourself a little script that calls timezonefinder (s. readme for instructions on that) just with the bash arguments as input. See http://stackoverflow.com/questions/7521061/how-to-pass-a-bash-variable-to-python

from timezonefinder.

cnaslain avatar cnaslain commented on May 19, 2024

Thanks for tha answer; That's what I guessed. No way to directly call the timezonefinder.py directly.
I'm gonna see how to write my own little py script (I'm not familiar at all with python) using os.environ to get some parameters (here lat,lon) and call timezonefinder.py...
It would be great that timezonefinder.py could be called by command line directly (or thru another file). Even if timezonefinder.py is a python script, the clients are not always python-based... it would increase the number of possible clients ;-)

from timezonefinder.

cnaslain avatar cnaslain commented on May 19, 2024

I tried with this little wrapper:
#!/usr/bin/env python
import sys
import os
from timezonefinder import TimezoneFinder

if len(sys.argv) < 2:
print 'Usage: ' + sys.argv[0] + ' '
sys.exit(1)

def main():
tf = TimezoneFinder()
latitude = float(sys.argv[1])
longitude = float(sys.argv[2])
print 'Looking for TZ at lat=',latitude,' lon=',longitude
tz = tf.timezone_at(lng=longitude, lat=latitude)
print 'Timezone=',tz

if name == 'main':
main()

And call it with:
python callbyenv.py 45 -1

Get:
Looking for TZ at lat= 45.0 lon= -1.0
Traceback (most recent call last):
File "callbyenv.py", line 19, in
main()
File "callbyenv.py", line 15, in main
tz = tf.timezone_at(lng=longitude, lat=latitude)
File "/home/opt/timezonefinder/timezonefinder/functional.py", line 27, in wrapper
return func(*args, **kwargs)
File "/home/opt/timezonefinder/timezonefinder/timezonefinder.py", line 448, in timezone_at
possible_polygons = self.shortcuts_of(lng, lat)
File "/home/opt/timezonefinder/timezonefinder/timezonefinder.py", line 169, in shortcuts_of
return fromfile(self.binary_file, dtype='<u2', count=nr_of_polygons)
TypeError: data type not understood

Sorry for my inexperienced in python language; but I cant figure out what's wrong with this; looks very close to the example.

from timezonefinder.

jannikmi avatar jannikmi commented on May 19, 2024

I am looking into this right now, but it might take a little while.

from timezonefinder.

jannikmi avatar jannikmi commented on May 19, 2024

Ok, I called this script:

#!/usr/bin/env python
import sys
from timezonefinder import TimezoneFinder

if len(sys.argv) < 2:
    print('Usage: ' + sys.argv[0])
    sys.exit(1)

tf = TimezoneFinder()
latitude = float(sys.argv[1])
longitude = float(sys.argv[2])
print('Looking for TZ at lat=',latitude,' lon=',longitude)
tz = tf.timezone_at(lng=longitude, lat=latitude)
print('Timezone=',tz)

with:
python3 scrapyard.py -45 1

and that gives me:

Looking for TZ at lat= -45.0  lon= 1.0
Timezone= None

So I guess there is something wrong with your installation (maybe numpy is missing?!). Try installing with pip or conda. That should work.

I think about including a little script in the next release. Thanks for the suggestion.

from timezonefinder.

cnaslain avatar cnaslain commented on May 19, 2024

Argh, doesn't work on my CentOS 6.8 with Python 2.6.6-66.el6_8. Still get the same error.

I've downloaded Python 3.0.1 version from https://www.python.org/ftp/python/3.0.1/Python-3.0.1.tgz; and built it on my CentOS 6.8 OS. Here is the result with Python3:

$ /opt/Python-3.0.1/python scrapyard.py -45 1
Traceback (most recent call last):
File "scrapyard.py", line 3, in
from timezonefinder import TimezoneFinder
File "/home/opt/timezonefinder/timezonefinder/init.py", line 3, in
from .timezonefinder import TimezoneFinder
File "/home/opt/timezonefinder/timezonefinder/timezonefinder.py", line 8, in
from numpy import array, empty, fromfile
ImportError: No module named numpy

The numpy error is wired; I've installed it using pip install numpy:
$ pip install numpy
Requirement already satisfied: numpy in /usr/lib64/python2.6/site-packages

Is there a path to specify somewhere? An environment variable to set?

EDIT: Ok; I've found that Python 3 requires numpy 1.5.0; I've got numpy 1.4.1 with Python 2.6.6. I'm gonna compile the numpy 1.5.0 and try to link it with my new Python 3...

from timezonefinder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.