2015-07-15 13:12:32 -04:00
|
|
|
import config
|
2015-07-16 20:55:36 -04:00
|
|
|
from datetime import timedelta, datetime
|
|
|
|
import parsedatetime
|
2015-07-15 13:12:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
def get_pydruid_client():
|
|
|
|
from pydruid import client
|
|
|
|
return client.PyDruid(
|
|
|
|
"http://{0}:{1}/".format(config.DRUID_HOST, config.DRUID_PORT),
|
|
|
|
config.DRUID_BASE_ENDPOINT)
|
|
|
|
|
|
|
|
|
2015-07-16 20:55:36 -04:00
|
|
|
def parse_human_datetime(s):
|
|
|
|
"""
|
|
|
|
Use the parsedatetime lib to return ``datetime.datetime`` from human
|
|
|
|
generated strings
|
|
|
|
|
|
|
|
>>> parse_human_datetime("now") <= datetime.now()
|
|
|
|
True
|
|
|
|
"""
|
|
|
|
cal = parsedatetime.Calendar()
|
2015-07-17 02:46:00 -04:00
|
|
|
return dttm_from_timtuple(cal.parse(s)[0])
|
|
|
|
|
|
|
|
|
|
|
|
def dttm_from_timtuple(d):
|
2015-07-16 20:55:36 -04:00
|
|
|
return datetime(
|
|
|
|
d.tm_year, d.tm_mon, d.tm_mday, d.tm_hour, d.tm_min, d.tm_sec)
|
2015-07-17 02:46:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
def parse_human_timedelta(s):
|
|
|
|
"""
|
|
|
|
Use the parsedatetime lib to return ``datetime.datetime`` from human
|
|
|
|
generated strings
|
|
|
|
|
|
|
|
>>> parse_human_datetime("now") <= datetime.now()
|
|
|
|
True
|
|
|
|
"""
|
|
|
|
cal = parsedatetime.Calendar()
|
|
|
|
dttm = dttm_from_timtuple(datetime.now().timetuple())
|
|
|
|
d = cal.parse(s, dttm)[0]
|
|
|
|
d = datetime(
|
|
|
|
d.tm_year, d.tm_mon, d.tm_mday, d.tm_hour, d.tm_min, d.tm_sec)
|
|
|
|
return d - dttm
|