예제 #1
0
import requests
import json
import timezonefinder

# req = requests.get('http://api.geonames.org/timezoneJSON?lat=47.01&lng=10.2&username=demo')
# req = req.json()
# print(req)

from timezonefinder import TimezoneFinder

TimezoneFinder.using_numba()  # this is a static method returning True or False

tf = TimezoneFinder()
# tf = TimezoneFinder(in_memory=True) # to use the faster "in-memory" mode
# tf = TimezoneFinder(bin_file_location='path/to/files') # to use data files from another location

longitude, latitude = 13.358, 52.5061
print(tf.timezone_at(lng=55.028395, lat=61.646646))  # returns 'Europe/Berlin'
print(tf.certain_timezone_at(lng=longitude,
                             lat=latitude))  # returns 'Europe/Berlin'
예제 #2
0
def check_timezone_gps(locations):
    tf = TimezoneFinder(in_memory=True)
    TimezoneFinder.using_numba()
    return tf.timezone_at(lng=locations.longitude, lat=locations.latitude)
예제 #3
0
from timezonefinder import TimezoneFinder

tf = TimezoneFinder(in_memory=True)
TimezoneFinder.using_numba()


def getTimezone(df):
    timezone = tf.timezone_at(lng=df['deviceLongitude'],
                              lat=df['deviceLatitude'])
    return timezone


def getLocaltime(df):
    localtime = df['time'].tz_convert(df['timezone'])
    return localtime


ua_geo['timezone'] = ua_geo.apply(getTimezone, axis=1)

ua_geo['time'] = pd.DatetimeIndex(
    pd.to_datetime(ua_geo['UTCtimestamp'], unit='ms')).tz_localize('UTC')
ua_geo['time'] = ua_geo.apply(getLocaltime, axis=1)
    series_tables.append(_i[0])

print series_tables

print workout_tables

import datetime
import pytz

from decimal import Decimal

from timezonefinder import TimezoneFinder

tf = TimezoneFinder()

print TimezoneFinder.using_numba()

# add timezone
for _table in workout_tables:
    failed = 0
    print _table
    query = "select start_latitude, start_longitude, workoutId from {}".format(
        _table)
    cur.execute(query)
    _tmp = cur.fetchall()
    workoutIds = []
    for _i in _tmp:
        if _i[0] == None or _i[1] == None:
            continue
        if _i[0] < -180 or _i[0] > 180:
            continue
예제 #5
0
from timezonefinder import TimezoneFinder

TimezoneFinder.using_numba()  # this is a static method returning True or False

tf = TimezoneFinder()
# or
tf = TimezoneFinder(in_memory=True)

longitude, latitude = 13.358, 52.5061
tf.timezone_at(lng=longitude, lat=latitude)  # returns 'Europe/Berlin'
tf.certain_timezone_at(lng=longitude, lat=latitude)  # returns 'Europe/Berlin'

longitude = 12.773955
latitude = 55.578595
tf.closest_timezone_at(lng=longitude, lat=latitude)  # returns 'Europe/Copenhagen'

longitude = 42.1052479
latitude = -16.622686
tf.closest_timezone_at(lng=longitude, lat=latitude, delta_degree=2, exact_computation=True, return_distances=True,
                       force_evaluation=True)

tf.get_geometry(tz_name='Africa/Addis_Ababa', coords_as_pairs=True)
tf.get_geometry(tz_id=400, use_id=True)


# To maximize the chances of getting a result in a Django view it might look like:

def find_timezone(request, lat, lng):
    lat = float(lat)
    lng = float(lng)