Skip to content

Commit

Permalink
feat: return datetime object for start_time and end_time
Browse files Browse the repository at this point in the history
Co-authored-by: Moritz Schott <moritz.schott@heigit.org>
  • Loading branch information
rp280 and SlowMo24 authored Nov 17, 2023
1 parent 76508d5 commit c70358c
Show file tree
Hide file tree
Showing 37 changed files with 65 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- support for python 3.12
- custom [retry](https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#urllib3.util.Retry) configuration
- start and end timestamp meta information of the client are now datetime objects

### Removed

Expand Down
12 changes: 9 additions & 3 deletions ohsome/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

"""OhsomeClient classes to build and handle requests to ohsome API"""
import datetime as dt
import json
from pathlib import Path
from typing import Union, Optional
Expand Down Expand Up @@ -140,7 +141,11 @@ def start_timestamp(self):
"""
if self._metadata is None:
self._query_metadata()
return self._metadata["extractRegion"]["temporalExtent"]["fromTimestamp"]
return dt.datetime.fromisoformat(
self._metadata["extractRegion"]["temporalExtent"]["fromTimestamp"].strip(
"Z"
)
)

@property
def end_timestamp(self):
Expand All @@ -150,8 +155,9 @@ def end_timestamp(self):
"""
if self._metadata is None:
self._query_metadata()
return self._metadata["extractRegion"]["temporalExtent"]["toTimestamp"]
# return dt.datetime.fromisoformat(end_timestamp.strip("Z"))
return dt.datetime.fromisoformat(
self._metadata["extractRegion"]["temporalExtent"]["toTimestamp"].strip("Z")
)

@property
def api_version(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:49 GMT
- Fri, 17 Nov 2023 11:28:23 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:47 GMT
- Fri, 17 Nov 2023 11:28:23 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interactions:
- request:
body: bcircles=0%3A8.678770065307615%2C49.414435400453954%2C100%7C1%3A8.697137832641602%2C49.41007968889129%2C150&time=2023-11-11T22%3A00Z&filter=amenity%3Drestaurant+and+type%3Away
body: bcircles=0%3A8.678770065307615%2C49.414435400453954%2C100%7C1%3A8.697137832641602%2C49.41007968889129%2C150&time=2023-11-11T22%3A00%3A00&filter=amenity%3Drestaurant+and+type%3Away
headers:
Accept:
- '*/*'
Expand All @@ -9,7 +9,7 @@ interactions:
Connection:
- keep-alive
Content-Length:
- '175'
- '179'
Content-Type:
- application/x-www-form-urlencoded
user-agent:
Expand Down Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:49 GMT
- Fri, 17 Nov 2023 11:28:26 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:52 GMT
- Fri, 17 Nov 2023 11:28:32 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
10 changes: 5 additions & 5 deletions ohsome/test/cassettes/test_client/test_format_bboxes_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:53 GMT
- Fri, 17 Nov 2023 11:28:32 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -99,7 +99,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:53 GMT
- Fri, 17 Nov 2023 11:28:34 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -156,7 +156,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:55 GMT
- Fri, 17 Nov 2023 11:28:34 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -213,7 +213,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:55 GMT
- Fri, 17 Nov 2023 11:28:36 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -270,7 +270,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:55 GMT
- Fri, 17 Nov 2023 11:28:36 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:50 GMT
- Fri, 17 Nov 2023 11:28:26 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:51 GMT
- Fri, 17 Nov 2023 11:28:31 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:50 GMT
- Fri, 17 Nov 2023 11:28:27 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -102,7 +102,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:50 GMT
- Fri, 17 Nov 2023 11:28:27 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -159,7 +159,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:51 GMT
- Fri, 17 Nov 2023 11:28:29 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -216,7 +216,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:51 GMT
- Fri, 17 Nov 2023 11:28:29 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
2 changes: 1 addition & 1 deletion ohsome/test/cassettes/test_client/test_format_bpolys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:52 GMT
- Fri, 17 Nov 2023 11:28:31 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Thu, 16 Nov 2023 12:52:56 GMT
- Fri, 17 Nov 2023 11:28:37 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -115,7 +115,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Thu, 16 Nov 2023 12:52:56 GMT
- Fri, 17 Nov 2023 11:28:37 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
2 changes: 1 addition & 1 deletion ohsome/test/cassettes/test_client/test_user_agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:47 GMT
- Fri, 17 Nov 2023 11:28:22 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
uri: https://api.ohsome.org/v1/elements/geometry
response:
body:
string: "{\n \"timestamp\" : \"2023-11-16T12:52:57.788982831\",\n \"status\"
string: "{\n \"timestamp\" : \"2023-11-17T11:28:39.812288772\",\n \"status\"
: 413,\n \"message\" : \"The given query is too large in respect to the given
timeout. Please use a smaller region and/or coarser time period.\",\n \"requestUrl\"
: \"https://api.ohsome.org/v1/elements/geometry\"\n}"
Expand All @@ -44,7 +44,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Thu, 16 Nov 2023 12:52:57 GMT
- Fri, 17 Nov 2023 11:28:39 GMT
Server:
- Apache
Strict-Transport-Security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:53:04 GMT
- Fri, 17 Nov 2023 11:28:47 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
uri: https://api.ohsome.org/v1/elements/count/groupBy/tag
response:
body:
string: "{\n \"timestamp\" : \"2023-11-16T12:53:04.15640038\",\n \"status\"
string: "{\n \"timestamp\" : \"2023-11-17T11:28:47.569104003\",\n \"status\"
: 400,\n \"message\" : \"You need to give one groupByKey parameter, if you
want to use groupBy/tag.\",\n \"requestUrl\" : \"https://api.ohsome.org/v1/elements/count/groupBy/tag\"\n}"
headers:
Expand All @@ -41,7 +41,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:53:04 GMT
- Fri, 17 Nov 2023 11:28:47 GMT
Server:
- Apache
Strict-Transport-Security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interactions:
Content-Type:
- text/html
Date:
- Thu, 16 Nov 2023 12:52:57 GMT
- Fri, 17 Nov 2023 11:28:39 GMT
ETag:
- '"25c-5c7180820e5fc"'
Keep-Alive:
Expand Down
4 changes: 2 additions & 2 deletions ohsome/test/cassettes/test_exceptions/test_log_bpolys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
uri: https://api.ohsome.org/v1/elements/count
response:
body:
string: "{\n \"timestamp\" : \"2023-11-16T12:52:57.984489101\",\n \"status\"
string: "{\n \"timestamp\" : \"2023-11-17T11:28:40.637302314\",\n \"status\"
: 413,\n \"message\" : \"The given query is too large in respect to the given
timeout. Please use a smaller region and/or coarser time period.\",\n \"requestUrl\"
: \"https://api.ohsome.org/v1/elements/count\"\n}"
Expand All @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:52:57 GMT
- Fri, 17 Nov 2023 11:28:39 GMT
Server:
- Apache
Strict-Transport-Security:
Expand Down
4 changes: 2 additions & 2 deletions ohsome/test/cassettes/test_exceptions/test_timeout_error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
uri: https://api.ohsome.org/v1/elements/geometry
response:
body:
string: "{\n \"timestamp\" : \"2023-11-16T12:52:57.463419205\",\n \"status\"
string: "{\n \"timestamp\" : \"2023-11-17T11:28:39.141569932\",\n \"status\"
: 413,\n \"message\" : \"The given query is too large in respect to the given
timeout. Please use a smaller region and/or coarser time period.\",\n \"requestUrl\"
: \"https://api.ohsome.org/v1/elements/geometry\"\n}"
Expand All @@ -44,7 +44,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Thu, 16 Nov 2023 12:52:56 GMT
- Fri, 17 Nov 2023 11:28:38 GMT
Server:
- Apache
Strict-Transport-Security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Thu, 16 Nov 2023 12:53:13 GMT
- Fri, 17 Nov 2023 11:29:01 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Thu, 16 Nov 2023 12:53:13 GMT
- Fri, 17 Nov 2023 11:29:01 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Thu, 16 Nov 2023 12:53:12 GMT
- Fri, 17 Nov 2023 11:28:59 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:53:05 GMT
- Fri, 17 Nov 2023 11:28:49 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:53:08 GMT
- Fri, 17 Nov 2023 11:28:54 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:53:08 GMT
- Fri, 17 Nov 2023 11:28:56 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:53:05 GMT
- Fri, 17 Nov 2023 11:28:50 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:53:06 GMT
- Fri, 17 Nov 2023 11:28:52 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Nov 2023 12:53:08 GMT
- Fri, 17 Nov 2023 11:28:54 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Loading

0 comments on commit c70358c

Please sign in to comment.