Commit 638ba63a authored by Charles de Beauchesne's avatar Charles de Beauchesne

Version 1.0.1 : add find_closest_documents

parent 2e763514
Pipeline #54251888 passed with stage
in 2 minutes and 25 seconds
......@@ -799,6 +799,32 @@ class CampBot(object):
return list(result.values())
def find_closest_documents(self, constructor, longitude, latitude, buffer, filters=None):
fake_object = {
"geometry": {
"geom": '{' + '"type":"Point", "coordinates": [{}, {}]'.format(longitude, latitude) + '}'
}
}
filters = filters or {}
filters["bbox"] = ",".join(map(str, [
longitude - buffer,
latitude - buffer,
longitude + buffer,
latitude + buffer
]))
result = []
for document in self.wiki.get_documents(constructor=constructor, filters=filters):
result.append({
"document": document,
"distance": utils.compute_distance(fake_object, document)
})
result.sort(key=lambda item: item["distance"])
return result
def _parse_filter(url):
url = url.replace("https://www.camptocamp.org/", "")
......
......@@ -6,7 +6,7 @@ with open('requirements.txt') as f:
setup(
name='campbot',
version="1.0.0",
version="1.1.0",
packages=find_packages(),
author="Charles de Beauchesne",
author_email="charles.de.beauchesne@gmail.com",
......
......@@ -306,3 +306,11 @@ def test_weird(fix_requests, fix_input):
f.write("123|1\n")
bot.get_new_contributors()
def test_get_closest_documents(fix_requests):
from campbot import CampBot, objects
bot = CampBot()
bot.find_closest_documents(objects.Waypoint, 289284, 6175526, 2000)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment