Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Add date parameter to query builder #125

Merged
merged 6 commits into from
Nov 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use fromisoformat first
  • Loading branch information
Evan Derickson committed Apr 28, 2020
commit 93afe66da2f40725c621650263122d10578d637d
8 changes: 5 additions & 3 deletions overpass/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ def get(self, query, responseformat="geojson", verbosity="body", build=True, dat
or allow the programmer to specify full query manually (False)
:param date: a date with an optional time. Example: 2020-04-27 or 2020-04-27T00:00:00Z
"""
if date:
if date and not isinstance(date, datetime):
# If date is given and is not already a datetime, attempt to parse from string
try:
date = datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ')
date = datetime.fromisoformat(date)
except ValueError:
date = datetime.strptime(date, '%Y-%m-%d')
# The 'Z' in a standard overpass date will through fromisoformat() off
date = datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ')
# Construct full Overpass query
if build:
full_query = self._construct_ql_query(
Expand Down