Created
October 26, 2015 05:15
-
-
Save ivey/50223c025111475369d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import floor | |
from datetime import datetime, timedelta | |
from time import mktime | |
import plugins | |
def _initialise(bot): | |
plugins.register_handler(_handle_cp_action) | |
def _handle_cp_action(bot, event, command): | |
if event.text.startswith('+cp'): | |
cps = current_cycle() | |
n = next_checkpoint(cps) | |
c = cycle_end(cps) | |
yield from bot.coro_send_message(event.conv, _("Next checkpoint is {} <b>{}</b>.\nThis cycle ends {} <b>{}</b>.").format(n['date'], n['time'], c['date'], c['time'])) | |
else: | |
pass | |
EPOCH=1389150000000 | |
CYCLE_LENGTH=630000000 | |
CHECKPOINT_LENGTH=18000 | |
def current_cycle(): | |
present = datetime.now() | |
tt = datetime.timetuple(present) | |
now = mktime(tt) * 1000 | |
cycle = floor((now - EPOCH) / CYCLE_LENGTH) | |
cycle_display = cycle + 1 | |
start = datetime.fromtimestamp(CHECKPOINT_LENGTH+((EPOCH + (cycle*CYCLE_LENGTH))/1000)) | |
year = start.year | |
checkpoints = [] | |
for i in range(0, 35): | |
next = (start > present) and (present + timedelta(seconds=CHECKPOINT_LENGTH)) > start | |
cp = { | |
'date': start.strftime('%a %d %b'), | |
'time': start.strftime('%I:%M%p'), | |
'next': next, | |
'past': (start < present) | |
} | |
checkpoints.append(cp) | |
start = start + timedelta(seconds=CHECKPOINT_LENGTH) | |
return checkpoints | |
def next_checkpoint(cps): | |
future = [cp for cp in cps if cp['past'] == False] | |
return future[0] | |
def cycle_end(cps): | |
return cps[-1] | |
# def main(): | |
# cps = current_cycle() | |
# print next_checkpoint(cps) | |
# print cycle_end(cps) | |
# if __name__ == "__main__": | |
# main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment