NeoBase 0.35.1__tar.gz → 0.36.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {neobase-0.35.1/src/NeoBase.egg-info → neobase-0.36.1}/PKG-INFO +3 -1
- {neobase-0.35.1 → neobase-0.36.1}/README.rst +1 -0
- {neobase-0.35.1 → neobase-0.36.1}/pyproject.toml +3 -1
- {neobase-0.35.1 → neobase-0.36.1/src/NeoBase.egg-info}/PKG-INFO +3 -1
- {neobase-0.35.1 → neobase-0.36.1}/src/NeoBase.egg-info/SOURCES.txt +1 -0
- {neobase-0.35.1 → neobase-0.36.1}/src/NeoBase.egg-info/scm_file_list.json +15 -13
- neobase-0.36.1/src/NeoBase.egg-info/scm_version.json +8 -0
- {neobase-0.35.1 → neobase-0.36.1}/src/neobase/__main__.py +10 -8
- {neobase-0.35.1 → neobase-0.36.1}/src/neobase/neobase.py +108 -38
- {neobase-0.35.1 → neobase-0.36.1}/src/neobase/optd_por_public.csv +9125 -9118
- neobase-0.36.1/src/neobase/py.typed +0 -0
- neobase-0.36.1/src/neobase/version.py +3 -0
- neobase-0.35.1/src/NeoBase.egg-info/scm_version.json +0 -8
- neobase-0.35.1/src/neobase/version.py +0 -3
- {neobase-0.35.1 → neobase-0.36.1}/LICENSE +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/MANIFEST.in +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/_config.yml +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/doc/Makefile +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/doc/conf.py +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/doc/index.rst +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/doc/make.bat +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/setup.cfg +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/src/NeoBase.egg-info/dependency_links.txt +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/src/NeoBase.egg-info/entry_points.txt +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/src/NeoBase.egg-info/top_level.txt +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/src/neobase/__init__.py +0 -0
- {neobase-0.35.1 → neobase-0.36.1}/tox.ini +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: NeoBase
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.36.1
|
|
4
4
|
Summary: Python library to manipulate OpenTravelData
|
|
5
5
|
Author-email: Alex Prengère <alex.prengere@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/alexprengere/neobase
|
|
@@ -9,6 +9,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
9
9
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
10
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
11
11
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
12
|
+
Classifier: Typing :: Typed
|
|
12
13
|
Requires-Python: >=3.11
|
|
13
14
|
Description-Content-Type: text/x-rst
|
|
14
15
|
License-File: LICENSE
|
|
@@ -36,6 +37,7 @@ implementation:
|
|
|
36
37
|
- one Python module for easier distribution on clusters (like Hadoop)
|
|
37
38
|
- faster load time (5x)
|
|
38
39
|
- tested with pytest and tox
|
|
40
|
+
- passes static typing checks with ty
|
|
39
41
|
|
|
40
42
|
.. code:: python
|
|
41
43
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools>=71", "setuptools-scm[simple]>=
|
|
2
|
+
requires = ["setuptools>=71", "setuptools-scm[simple]>=10.1"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
@@ -18,6 +18,7 @@ classifiers = [
|
|
|
18
18
|
"Programming Language :: Python :: 3 :: Only",
|
|
19
19
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
20
20
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
21
|
+
"Typing :: Typed",
|
|
21
22
|
]
|
|
22
23
|
|
|
23
24
|
[project.scripts]
|
|
@@ -123,6 +124,7 @@ ignore = [
|
|
|
123
124
|
"ambiguous-unicode-character-string",
|
|
124
125
|
"collection-literal-concatenation",
|
|
125
126
|
"mutable-class-default",
|
|
127
|
+
"blanket-type-ignore",
|
|
126
128
|
]
|
|
127
129
|
preview = true
|
|
128
130
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: NeoBase
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.36.1
|
|
4
4
|
Summary: Python library to manipulate OpenTravelData
|
|
5
5
|
Author-email: Alex Prengère <alex.prengere@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/alexprengere/neobase
|
|
@@ -9,6 +9,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
9
9
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
10
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
11
11
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
12
|
+
Classifier: Typing :: Typed
|
|
12
13
|
Requires-Python: >=3.11
|
|
13
14
|
Description-Content-Type: text/x-rst
|
|
14
15
|
License-File: LICENSE
|
|
@@ -36,6 +37,7 @@ implementation:
|
|
|
36
37
|
- one Python module for easier distribution on clusters (like Hadoop)
|
|
37
38
|
- faster load time (5x)
|
|
38
39
|
- tested with pytest and tox
|
|
40
|
+
- passes static typing checks with ty
|
|
39
41
|
|
|
40
42
|
.. code:: python
|
|
41
43
|
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": [
|
|
3
|
-
"
|
|
3
|
+
".github/workflows/pre-commit.yml",
|
|
4
|
+
".github/workflows/python-package.yml",
|
|
5
|
+
".gitignore",
|
|
4
6
|
".pre-commit-config.yaml",
|
|
7
|
+
"LICENSE",
|
|
5
8
|
"MANIFEST.in",
|
|
6
9
|
"README.rst",
|
|
7
|
-
"update_data.sh",
|
|
8
10
|
"_config.yml",
|
|
9
|
-
"pyproject.toml",
|
|
10
|
-
"LICENSE",
|
|
11
|
-
".gitignore",
|
|
12
|
-
".github/workflows/python-package.yml",
|
|
13
|
-
"tests/test_neobase.py",
|
|
14
|
-
"tests/conftest.py",
|
|
15
|
-
"doc/index.rst",
|
|
16
|
-
"doc/conf.py",
|
|
17
11
|
"doc/Makefile",
|
|
12
|
+
"doc/conf.py",
|
|
13
|
+
"doc/index.rst",
|
|
18
14
|
"doc/make.bat",
|
|
19
|
-
"
|
|
20
|
-
"src/neobase/neobase.py",
|
|
15
|
+
"pyproject.toml",
|
|
21
16
|
"src/neobase/__init__.py",
|
|
17
|
+
"src/neobase/__main__.py",
|
|
18
|
+
"src/neobase/neobase.py",
|
|
19
|
+
"src/neobase/optd_por_public.csv",
|
|
20
|
+
"src/neobase/py.typed",
|
|
22
21
|
"src/neobase/version.py",
|
|
23
|
-
"
|
|
22
|
+
"tests/conftest.py",
|
|
23
|
+
"tests/test_neobase.py",
|
|
24
|
+
"tox.ini",
|
|
25
|
+
"update_data.sh"
|
|
24
26
|
]
|
|
25
27
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/python
|
|
2
2
|
|
|
3
3
|
import sys
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
|
|
4
6
|
from neobase import NeoBase, __version__
|
|
5
7
|
|
|
6
8
|
|
|
7
|
-
def main():
|
|
9
|
+
def main(argv: Sequence[str] | None = None) -> None:
|
|
8
10
|
import argparse
|
|
9
11
|
|
|
10
12
|
parser = argparse.ArgumentParser(prog="NeoBase")
|
|
@@ -16,11 +18,11 @@ def main():
|
|
|
16
18
|
parser.add_argument(
|
|
17
19
|
"keys",
|
|
18
20
|
nargs="+",
|
|
19
|
-
help="
|
|
21
|
+
help="list of IATA codes",
|
|
20
22
|
)
|
|
21
23
|
parser.add_argument(
|
|
22
24
|
"--date",
|
|
23
|
-
help="
|
|
25
|
+
help="reference date to compute active airports, format is YYYY-MM-DD",
|
|
24
26
|
)
|
|
25
27
|
parser.add_argument(
|
|
26
28
|
"-f",
|
|
@@ -44,7 +46,7 @@ def main():
|
|
|
44
46
|
"-c",
|
|
45
47
|
"--case-sensitive",
|
|
46
48
|
action="store_true",
|
|
47
|
-
help="
|
|
49
|
+
help="make the matching case-sensitive with --field",
|
|
48
50
|
)
|
|
49
51
|
parser.add_argument(
|
|
50
52
|
"-r",
|
|
@@ -60,7 +62,7 @@ def main():
|
|
|
60
62
|
help="when used, the output will look like a CSV containing those fields",
|
|
61
63
|
)
|
|
62
64
|
|
|
63
|
-
args = parser.parse_args()
|
|
65
|
+
args = parser.parse_args(argv)
|
|
64
66
|
G = NeoBase(date=args.date)
|
|
65
67
|
|
|
66
68
|
if args.show:
|
|
@@ -84,9 +86,9 @@ def main():
|
|
|
84
86
|
if not args.case_sensitive:
|
|
85
87
|
needle = needle.lower()
|
|
86
88
|
haystack = haystack.lower()
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (needle in
|
|
89
|
+
# --word means will look in words list, not substrings
|
|
90
|
+
haystack_ = haystack.split() if args.word else haystack
|
|
91
|
+
if (needle in haystack_) is args.invert_match:
|
|
90
92
|
continue
|
|
91
93
|
if args.show:
|
|
92
94
|
w.writerow(G.get(p, f) for f in args.show)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/python
|
|
2
|
-
|
|
3
2
|
"""
|
|
4
3
|
GeoBase. Rebooted.
|
|
5
4
|
|
|
@@ -22,10 +21,10 @@ import operator
|
|
|
22
21
|
from datetime import datetime
|
|
23
22
|
from math import pi, cos, sin, asin, sqrt, fsum
|
|
24
23
|
from itertools import starmap, pairwise
|
|
25
|
-
from typing import NamedTuple
|
|
24
|
+
from typing import NamedTuple, TypeAlias, Any, cast
|
|
26
25
|
import csv
|
|
27
26
|
import heapq
|
|
28
|
-
from collections.abc import Callable, Sequence
|
|
27
|
+
from collections.abc import Callable, Iterable, Iterator, Sequence
|
|
29
28
|
|
|
30
29
|
from functools import partial
|
|
31
30
|
|
|
@@ -42,6 +41,11 @@ OPTD_POR_URL = (
|
|
|
42
41
|
_DEF_OPTD_POR_FILE = "optd_por_public.csv"
|
|
43
42
|
_DEFAULT_RADIUS = 50
|
|
44
43
|
|
|
44
|
+
FieldValue: TypeAlias = Any
|
|
45
|
+
PointData: TypeAlias = dict[str, FieldValue]
|
|
46
|
+
Splitter: TypeAlias = Callable[[str], FieldValue]
|
|
47
|
+
DistanceResult: TypeAlias = tuple[float, str]
|
|
48
|
+
|
|
45
49
|
|
|
46
50
|
class LatLng(NamedTuple):
|
|
47
51
|
lat: float
|
|
@@ -60,7 +64,7 @@ class NeoBase:
|
|
|
60
64
|
"""Main structure, a wrapper around a dict, with dict-like behavior."""
|
|
61
65
|
|
|
62
66
|
KEY = 0 # iata_code
|
|
63
|
-
FIELDS: Sequence[tuple[str, int,
|
|
67
|
+
FIELDS: Sequence[tuple[str, int, Splitter | None]] = (
|
|
64
68
|
("iata_code", 0, None),
|
|
65
69
|
("name", 6, None),
|
|
66
70
|
("lat", 8, None),
|
|
@@ -80,7 +84,7 @@ class NeoBase:
|
|
|
80
84
|
DUPLICATES = getenv("OPTD_POR_DUPLICATES", "1") == "1"
|
|
81
85
|
|
|
82
86
|
@staticmethod
|
|
83
|
-
def skip(row, date):
|
|
87
|
+
def skip(row: Sequence[str], date: str) -> bool:
|
|
84
88
|
date_from, date_until = row[13], row[14]
|
|
85
89
|
if date_from and date < date_from:
|
|
86
90
|
return True
|
|
@@ -88,7 +92,12 @@ class NeoBase:
|
|
|
88
92
|
return True
|
|
89
93
|
return False
|
|
90
94
|
|
|
91
|
-
def __init__(
|
|
95
|
+
def __init__(
|
|
96
|
+
self,
|
|
97
|
+
rows: Iterable[str] | None = None,
|
|
98
|
+
date: str | None = None,
|
|
99
|
+
duplicates: bool | None = None,
|
|
100
|
+
) -> None:
|
|
92
101
|
if date is None:
|
|
93
102
|
date = getenv("OPTD_POR_DATE", datetime.today().strftime("%Y-%m-%d"))
|
|
94
103
|
|
|
@@ -107,11 +116,16 @@ class NeoBase:
|
|
|
107
116
|
self._data = self.load(rows, date, duplicates)
|
|
108
117
|
|
|
109
118
|
@staticmethod
|
|
110
|
-
def _empty_value():
|
|
119
|
+
def _empty_value() -> PointData:
|
|
111
120
|
return {"__dup__": set()}
|
|
112
121
|
|
|
113
122
|
@classmethod
|
|
114
|
-
def load(
|
|
123
|
+
def load(
|
|
124
|
+
cls,
|
|
125
|
+
f: Iterable[str],
|
|
126
|
+
date: str,
|
|
127
|
+
duplicates: bool,
|
|
128
|
+
) -> dict[str, PointData]:
|
|
115
129
|
"""Building a dictionary of geographical data from optd_por.
|
|
116
130
|
|
|
117
131
|
>>> import os.path as op
|
|
@@ -126,7 +140,7 @@ class NeoBase:
|
|
|
126
140
|
fields, key_c, skip = cls.FIELDS, cls.KEY, cls.skip
|
|
127
141
|
empty_value = cls._empty_value
|
|
128
142
|
|
|
129
|
-
data = {}
|
|
143
|
+
data: dict[str, PointData] = {}
|
|
130
144
|
try:
|
|
131
145
|
next(f) # skipping first line
|
|
132
146
|
except StopIteration:
|
|
@@ -163,15 +177,16 @@ class NeoBase:
|
|
|
163
177
|
data[key] = d
|
|
164
178
|
else:
|
|
165
179
|
prev_d = data[key]
|
|
166
|
-
|
|
180
|
+
prev_d_dup = cast("set[str]", prev_d["__dup__"])
|
|
181
|
+
new_key = f"{key}@{1 + len(prev_d_dup)}"
|
|
167
182
|
data[new_key] = d
|
|
168
183
|
# Exchanging duplicata information
|
|
169
|
-
d["__dup__"] =
|
|
170
|
-
|
|
184
|
+
d["__dup__"] = prev_d_dup | {key}
|
|
185
|
+
prev_d_dup.add(new_key)
|
|
171
186
|
|
|
172
187
|
return data
|
|
173
188
|
|
|
174
|
-
def __iter__(self):
|
|
189
|
+
def __iter__(self) -> Iterator[str]:
|
|
175
190
|
"""Returns iterator of all keys in the base.
|
|
176
191
|
|
|
177
192
|
:returns: the iterator of all keys
|
|
@@ -182,7 +197,7 @@ class NeoBase:
|
|
|
182
197
|
"""
|
|
183
198
|
return iter(self._data)
|
|
184
199
|
|
|
185
|
-
def __contains__(self, key):
|
|
200
|
+
def __contains__(self, key: str | None) -> bool:
|
|
186
201
|
"""Test if a key is in the base.
|
|
187
202
|
|
|
188
203
|
:param key: the key of to be tested
|
|
@@ -202,7 +217,7 @@ class NeoBase:
|
|
|
202
217
|
key = key.upper()
|
|
203
218
|
return key in self._data
|
|
204
219
|
|
|
205
|
-
def __bool__(self):
|
|
220
|
+
def __bool__(self) -> bool:
|
|
206
221
|
"""Testing structure emptiness.
|
|
207
222
|
|
|
208
223
|
:returns: a boolean
|
|
@@ -214,7 +229,7 @@ class NeoBase:
|
|
|
214
229
|
"""
|
|
215
230
|
return bool(self._data)
|
|
216
231
|
|
|
217
|
-
def __len__(self):
|
|
232
|
+
def __len__(self) -> int:
|
|
218
233
|
"""Testing structure size.
|
|
219
234
|
|
|
220
235
|
:returns: a integer
|
|
@@ -225,7 +240,7 @@ class NeoBase:
|
|
|
225
240
|
"""
|
|
226
241
|
return len(self._data)
|
|
227
242
|
|
|
228
|
-
def keys(self):
|
|
243
|
+
def keys(self) -> Iterator[str]:
|
|
229
244
|
"""Returns iterator of all keys in the base.
|
|
230
245
|
|
|
231
246
|
:returns: the iterator of all keys
|
|
@@ -236,7 +251,7 @@ class NeoBase:
|
|
|
236
251
|
"""
|
|
237
252
|
return iter(self)
|
|
238
253
|
|
|
239
|
-
def set(self, key, **data):
|
|
254
|
+
def set(self, key: str | None, **data: FieldValue) -> None:
|
|
240
255
|
"""Set information.
|
|
241
256
|
|
|
242
257
|
>>> b = NeoBase()
|
|
@@ -249,13 +264,19 @@ class NeoBase:
|
|
|
249
264
|
>>> b.get('Wow!', 'name')
|
|
250
265
|
'test'
|
|
251
266
|
"""
|
|
252
|
-
if key is
|
|
253
|
-
|
|
267
|
+
if key is None:
|
|
268
|
+
return
|
|
269
|
+
key = key.upper()
|
|
254
270
|
if key not in self:
|
|
255
271
|
self._data[key] = self._empty_value()
|
|
256
272
|
self._data[key].update(data)
|
|
257
273
|
|
|
258
|
-
def get(
|
|
274
|
+
def get(
|
|
275
|
+
self,
|
|
276
|
+
key: str | None,
|
|
277
|
+
field: str | None = None,
|
|
278
|
+
default: object = _sentinel,
|
|
279
|
+
) -> Any:
|
|
259
280
|
"""Get data from structure.
|
|
260
281
|
|
|
261
282
|
>>> b = NeoBase()
|
|
@@ -285,7 +306,13 @@ class NeoBase:
|
|
|
285
306
|
else:
|
|
286
307
|
return res
|
|
287
308
|
|
|
288
|
-
def get_location(
|
|
309
|
+
def get_location(
|
|
310
|
+
self,
|
|
311
|
+
key: str | None,
|
|
312
|
+
lat_field: str = "lat",
|
|
313
|
+
lng_field: str = "lng",
|
|
314
|
+
default: object = _sentinel,
|
|
315
|
+
) -> LatLng | None:
|
|
289
316
|
"""Get None or the geocode.
|
|
290
317
|
|
|
291
318
|
>>> b = NeoBase()
|
|
@@ -300,12 +327,12 @@ class NeoBase:
|
|
|
300
327
|
# Unless default is set, we raise an Exception
|
|
301
328
|
if default is _sentinel:
|
|
302
329
|
raise UnknownKeyError(f"Key not found: {key}")
|
|
303
|
-
return default
|
|
330
|
+
return cast("LatLng | None", default)
|
|
304
331
|
|
|
305
332
|
try:
|
|
306
333
|
loc = LatLng(
|
|
307
|
-
float(d[lat_field]),
|
|
308
|
-
float(d[lng_field]),
|
|
334
|
+
float(cast("str", d[lat_field])),
|
|
335
|
+
float(cast("str", d[lng_field])),
|
|
309
336
|
)
|
|
310
337
|
|
|
311
338
|
except (ValueError, TypeError, KeyError):
|
|
@@ -318,7 +345,10 @@ class NeoBase:
|
|
|
318
345
|
return loc
|
|
319
346
|
|
|
320
347
|
@staticmethod
|
|
321
|
-
def distance_between_locations(
|
|
348
|
+
def distance_between_locations(
|
|
349
|
+
l0: LatLng | None,
|
|
350
|
+
l1: LatLng | None,
|
|
351
|
+
) -> float | None:
|
|
322
352
|
"""Great circle distance
|
|
323
353
|
|
|
324
354
|
:param l0: the LatLng tuple of the first location
|
|
@@ -352,7 +382,11 @@ class NeoBase:
|
|
|
352
382
|
)
|
|
353
383
|
)
|
|
354
384
|
|
|
355
|
-
def distance(
|
|
385
|
+
def distance(
|
|
386
|
+
self,
|
|
387
|
+
*keys: str | None,
|
|
388
|
+
default: object = _sentinel,
|
|
389
|
+
) -> float | None:
|
|
356
390
|
"""Compute distance between two elements.
|
|
357
391
|
|
|
358
392
|
This is just a wrapper between the original haversine
|
|
@@ -372,11 +406,15 @@ class NeoBase:
|
|
|
372
406
|
except KeyError:
|
|
373
407
|
if default is _sentinel:
|
|
374
408
|
raise
|
|
375
|
-
return default
|
|
409
|
+
return cast("float | None", default)
|
|
376
410
|
else:
|
|
377
|
-
return fsum(starmap(self.distance_between_locations, pairwise(locations)))
|
|
411
|
+
return fsum(starmap(self.distance_between_locations, pairwise(locations))) # type: ignore
|
|
378
412
|
|
|
379
|
-
def _build_distances(
|
|
413
|
+
def _build_distances(
|
|
414
|
+
self,
|
|
415
|
+
lat_lng_ref: LatLng | None,
|
|
416
|
+
keys: Iterable[str | None],
|
|
417
|
+
) -> Iterator[DistanceResult]:
|
|
380
418
|
"""
|
|
381
419
|
Compute the iterable of (dist, keys) of a reference
|
|
382
420
|
lat_lng and a list of keys. Keys which have not valid
|
|
@@ -392,18 +430,30 @@ class NeoBase:
|
|
|
392
430
|
data_get = self._data.get
|
|
393
431
|
distance_between_locations = self.distance_between_locations
|
|
394
432
|
for key in keys:
|
|
395
|
-
|
|
433
|
+
if key is None:
|
|
434
|
+
continue
|
|
435
|
+
d = data_get(key.upper())
|
|
396
436
|
|
|
397
437
|
if d is None:
|
|
398
438
|
continue
|
|
399
439
|
try:
|
|
400
|
-
lat_lng =
|
|
440
|
+
lat_lng = LatLng(
|
|
441
|
+
float(cast("str", d["lat"])),
|
|
442
|
+
float(cast("str", d["lng"])),
|
|
443
|
+
)
|
|
401
444
|
except (ValueError, TypeError, KeyError):
|
|
402
445
|
continue
|
|
403
446
|
|
|
404
|
-
|
|
447
|
+
dist = distance_between_locations(lat_lng_ref, lat_lng)
|
|
448
|
+
if dist is not None:
|
|
449
|
+
yield dist, key
|
|
405
450
|
|
|
406
|
-
def find_near_location(
|
|
451
|
+
def find_near_location(
|
|
452
|
+
self,
|
|
453
|
+
lat_lng: LatLng | None,
|
|
454
|
+
radius: float = _DEFAULT_RADIUS,
|
|
455
|
+
from_keys: Iterable[str | None] | None = None,
|
|
456
|
+
) -> Iterator[DistanceResult]:
|
|
407
457
|
"""
|
|
408
458
|
Returns a list of nearby keys from a location (given
|
|
409
459
|
latidude and longitude), and a radius for the search.
|
|
@@ -429,7 +479,12 @@ class NeoBase:
|
|
|
429
479
|
if dist <= radius:
|
|
430
480
|
yield dist, key
|
|
431
481
|
|
|
432
|
-
def find_near(
|
|
482
|
+
def find_near(
|
|
483
|
+
self,
|
|
484
|
+
key: str | None,
|
|
485
|
+
radius: float = _DEFAULT_RADIUS,
|
|
486
|
+
from_keys: Iterable[str | None] | None = None,
|
|
487
|
+
) -> Iterator[DistanceResult]:
|
|
433
488
|
"""
|
|
434
489
|
Same as find_near_location, except the location is given
|
|
435
490
|
not by a lat/lng, but with its key, like ORY or SFO.
|
|
@@ -458,7 +513,12 @@ class NeoBase:
|
|
|
458
513
|
from_keys=from_keys,
|
|
459
514
|
)
|
|
460
515
|
|
|
461
|
-
def find_closest_from_location(
|
|
516
|
+
def find_closest_from_location(
|
|
517
|
+
self,
|
|
518
|
+
lat_lng: LatLng | None,
|
|
519
|
+
N: int = 1,
|
|
520
|
+
from_keys: Iterable[str | None] | None = None,
|
|
521
|
+
) -> Iterator[DistanceResult]:
|
|
462
522
|
"""
|
|
463
523
|
Concept close to find_near_location, but here we do not
|
|
464
524
|
look for the keys radius-close to a location,
|
|
@@ -485,7 +545,12 @@ class NeoBase:
|
|
|
485
545
|
|
|
486
546
|
yield from heapq.nsmallest(N, iterable)
|
|
487
547
|
|
|
488
|
-
def find_closest_from(
|
|
548
|
+
def find_closest_from(
|
|
549
|
+
self,
|
|
550
|
+
key: str | None,
|
|
551
|
+
N: int = 1,
|
|
552
|
+
from_keys: Iterable[str | None] | None = None,
|
|
553
|
+
) -> Iterator[DistanceResult]:
|
|
489
554
|
"""
|
|
490
555
|
Same as find_closest_from_location, except the location is given
|
|
491
556
|
not by a lat/lng, but with its key, like ORY or SFO.
|
|
@@ -517,7 +582,12 @@ class NeoBase:
|
|
|
517
582
|
from_keys=from_keys,
|
|
518
583
|
)
|
|
519
584
|
|
|
520
|
-
def find_with(
|
|
585
|
+
def find_with(
|
|
586
|
+
self,
|
|
587
|
+
conditions: Iterable[tuple[str, FieldValue]],
|
|
588
|
+
from_keys: Iterable[str | None] | None = None,
|
|
589
|
+
reverse: bool = False,
|
|
590
|
+
) -> Iterator[str | None]:
|
|
521
591
|
"""Get iterator of all keys with particular field.
|
|
522
592
|
|
|
523
593
|
For example, if you want to know all airports in Paris.
|