Skip to content

Instantly share code, notes, and snippets.

@guillermo-menjivar
Last active January 21, 2020 20:20
Show Gist options
  • Save guillermo-menjivar/70f26f14ca09f1f0ce7e4e86252f3c04 to your computer and use it in GitHub Desktop.
Save guillermo-menjivar/70f26f14ca09f1f0ce7e4e86252f3c04 to your computer and use it in GitHub Desktop.
test
import datetime
import calendar
from collections import namedtuple
predicate_string_template = "dt between \'{from_datetime}\' and \'{to_datetime}\' and timestamp between {from_datetime_epoch} and {to_datetime_epoch}"
def generate_datetime_ticker(window):
"""
retrieve_date: expects window to be always in minutes.
"""
epoch_f = lambda x : calendar.timegm(x.utctimetuple())
# snapshot current time
cur_time = datetime.datetime.utcnow()
cur_time_epoch = epoch_f(cur_time)
prev_time = cur_time - datetime.timedelta(minutes=window)
print(prev_time.strftime('%Y-%m-%d'))
prev_time_epoch = epoch_f(prev_time)
DatetimeWindow = namedtuple('DateWindow', 'previous_time previous_time_epoch current_time current_time_epoch')
ticker = DatetimeWindow(previous_time=prev_time, previous_time_epoch=prev_time_epoch,
current_time=cur_time, current_time_epoch=cur_time_epoch)
return ticker
t = generate_datetime_ticker(35)
rr = t.previous_time.strftime('%Y-%m-%d')
tt = t.current_time.strftime('%Y-%m-%d')
predicate_string = predicate_string_template.format(from_datetime=rr, to_datetime=tt, from_datetime_epoch=t.previous_time_epoch, to_datetime_epoch=t.current_time_epoch)
print(predicate_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment