From e0fc067024b8465e24c81d9af22e9384b89a408c Mon Sep 17 00:00:00 2001 From: Akio Taniguchi Date: Thu, 3 Nov 2022 08:34:38 +0000 Subject: [PATCH 1/2] #36 Update project dependencies --- poetry.lock | 36 +----------------------------------- pyproject.toml | 1 - 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/poetry.lock b/poetry.lock index f927a98..a376b80 100644 --- a/poetry.lock +++ b/poetry.lock @@ -256,32 +256,6 @@ ufo = ["fs (>=2.2.0,<3)"] unicode = ["unicodedata2 (>=14.0.0)"] woff = ["brotli (>=1.0.1)", "brotlicffi (>=0.8.0)", "zopfli (>=0.1.4)"] -[[package]] -name = "geographiclib" -version = "1.52" -description = "The geodesic routines from GeographicLib" -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "geopy" -version = "1.23.0" -description = "Python Geocoding Toolbox" -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -geographiclib = ">=1.49,<2" - -[package.extras] -dev = ["contextlib2", "coverage", "flake8 (>=3.6.0,<3.7.0)", "isort (>=4.3.4,<4.4.0)", "mock", "pytest (>=3.10)", "readme-renderer", "six", "sphinx", "sphinx-rtd-theme (>=0.4.0)", "statistics"] -dev-docs = ["readme-renderer", "sphinx", "sphinx-rtd-theme (>=0.4.0)"] -dev-lint = ["contextlib2", "flake8 (>=3.6.0,<3.7.0)", "isort (>=4.3.4,<4.4.0)", "mock", "six"] -dev-test = ["contextlib2", "coverage", "mock", "pytest (>=3.10)", "six", "statistics"] -timezone = ["pytz"] - [[package]] name = "h3" version = "3.7.4" @@ -1179,7 +1153,7 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "1.1" python-versions = ">=3.7.1, <3.11" -content-hash = "0d1eaaaae519a1f10b7fa45e5c111490a871e765406c0ab09742a3fb71a68c9f" +content-hash = "c057923ff3cbae0f8bcd5ce1732655566d1010c311e58490f66e2562d54dd382" [metadata.files] alabaster = [ @@ -1388,14 +1362,6 @@ fonttools = [ {file = "fonttools-4.38.0-py3-none-any.whl", hash = "sha256:820466f43c8be8c3009aef8b87e785014133508f0de64ec469e4efb643ae54fb"}, {file = "fonttools-4.38.0.zip", hash = "sha256:2bb244009f9bf3fa100fc3ead6aeb99febe5985fa20afbfbaa2f8946c2fbdaf1"}, ] -geographiclib = [ - {file = "geographiclib-1.52-py3-none-any.whl", hash = "sha256:8f441c527b0b8a26cd96c965565ff0513d1e4d9952b704bf449409e5015c77b7"}, - {file = "geographiclib-1.52.tar.gz", hash = "sha256:ac400d672b8954b0306bca890b088bb8ba2a757dc8133cca0b878f34b33b2740"}, -] -geopy = [ - {file = "geopy-1.23.0-py2.py3-none-any.whl", hash = "sha256:5dee9af0d1ad7019d2483a5f519ba415eaebc4010f271651790876d911a542f2"}, - {file = "geopy-1.23.0.tar.gz", hash = "sha256:62f14aaacbac313576167d4abdd74c667c04a64ccba4a9ef4599bf8954c998fc"}, -] h3 = [ {file = "h3-3.7.4-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:e61d3c6b1b66072f5b74d46dbee7df29daac6ce9738b9a6223a67dc577114515"}, {file = "h3-3.7.4-cp27-cp27m-manylinux2010_x86_64.whl", hash = "sha256:960cd005b8817314d95fbaff3e848a72385df4e3c6c9703ff99b08581c8def69"}, diff --git a/pyproject.toml b/pyproject.toml index d186de6..7263574 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,6 @@ astropy = [ { version = ">=4.3, <5.0", python = ">=3.7.1, <3.8" }, { version = "^5.0", python = ">=3.8, <3.11" }, ] -geopy = "^1.23" numpy = [ { version = ">=1.20, <1.22", python = ">=3.7.1, <3.8" }, { version = "^1.20", python = ">=3.8, <3.11" }, From e0c29325f608f5902d41da215d15db0f8b10d5a7 Mon Sep 17 00:00:00 2001 From: Akio Taniguchi Date: Thu, 3 Nov 2022 08:35:24 +0000 Subject: [PATCH 2/2] #36 Use EarthLocation.of_address to get location --- azely/location.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/azely/location.py b/azely/location.py index 1708bff..d8c5bd8 100644 --- a/azely/location.py +++ b/azely/location.py @@ -60,8 +60,8 @@ # dependent packages from astropy.coordinates import EarthLocation -from geopy import Nominatim -from geopy.exc import GeocoderServiceError +from astropy.coordinates.name_resolve import NameResolveError +from astropy.utils.data import conf from pytz import timezone from requests import ConnectionError, api from timezonefinder import TimezoneFinder @@ -87,7 +87,6 @@ # query instances tf = TimezoneFinder() -osm = Nominatim(user_agent="azely") # data classes @@ -188,12 +187,17 @@ def get_location_by_user(query: str) -> LocationDict: @cache_to(AZELY_LOCATION) def get_location_by_query(query: str, timeout: int) -> LocationDict: """Get location information from OpenStreetMap.""" + original_remote_timeout = conf.remote_timeout + try: - res = osm.geocode(query, timeout=timeout, namedetails=True).raw - except (AttributeError, GeocoderServiceError): + conf.remote_timeout = timeout + res = EarthLocation.of_address(query) + except NameResolveError: raise AzelyError(f"Failed to get location: {query}") + finally: + conf.remote_timeout = original_remote_timeout - return Location(res["namedetails"]["name"], res["lon"], res["lat"]).to_dict() + return Location(query, str(res.lon.value), str(res.lat.value)).to_dict() @cache_to(AZELY_LOCATION)