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

Commit aa8c426

Browse files
committed
use datetime.datetime or string as 'to'/'from_' parameter in report
1 parent 6387df2 commit aa8c426

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

atomx/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
from datetime import datetime
34
import requests
45
from .version import API_VERSION, VERSION
56
from . import models
@@ -58,7 +59,14 @@ def search(self, query):
5859
return search_result
5960

6061
def report(self, **kwargs):
61-
kwargs['from'] = kwargs['from_']
62+
if 'to' not in kwargs:
63+
kwargs['to'] = datetime.now()
64+
if isinstance(kwargs['to'], datetime): # TODO: support timezones
65+
kwargs['to'] = kwargs['to'].strftime("%Y-%m-%d %H:00:00Z")
66+
if isinstance(kwargs.get('from_'), datetime):
67+
kwargs['from'] = kwargs['from_'].strftime("%Y-%m-%d %H:00:00Z")
68+
else:
69+
kwargs['from'] = kwargs['from_']
6270
del kwargs['from_']
6371
r = self.session.post(self.api_endpoint + 'report', json=kwargs)
6472
if not r.ok:

0 commit comments

Comments
 (0)