#!/bin/python3 from contextlib import contextmanager import colorama import time import datetime import dateutil.tz @contextmanager def init_colorama(): """Set global foreground modifying ANSI codes. BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW, and RESET. """ # pylint: disable=exec-used,invalid-name colorama.init() for color, ansi in colorama.Fore.__dict__.items(): exec("global {0}; {0} = '{1}'".format(color, ansi)) yield for color in colorama.Fore.__dict__: exec("global {0}; {0} = ''".format(color)) colorama.deinit() def current_datetime(): """Return the current datetime, complete with tzinfo. Precision is one second. Timezone is the local timezone. """ return datetime.datetime.fromtimestamp(round(time.time()), dateutil.tz.tzlocal())