Last active
January 27, 2017 13:01
-
-
Save fuzzy-focus/4cd54c53a308c3c55182058f6a325503 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
#!/bin/env python | |
""" | |
"option definitions" and "time definitions could also have been placed in extra files and imported. | |
""" | |
#----------------------- | |
#- Option Definitions: - | |
#----------------------- | |
options = { | |
"night" : "--super-loud " + | |
"--relentless", | |
"morning" : "--morning", | |
"noon" : "--noonish", | |
"rest" : "--whatever", | |
} | |
#----------------------- | |
#- time definitions: - | |
#----------------------- | |
def night(): | |
yield from range(0,8) | |
yield 20 # just an example for how to return single values | |
yield from range(22,25) | |
def morning(): yield from range(8,12) | |
def noon(): yield from range(12,14) | |
def rest(): | |
yield from range(14,20) | |
yield 21 | |
#----------------------- | |
#- table creation - | |
#----------------------- | |
lookup_table = dict() | |
for optfun in (night, morning, noon, rest): | |
lookup_table.update({hour: options[optfun.__name__] for hour in optfun()}) | |
#----------------------- | |
#- Result - | |
#----------------------- | |
for i in range(25): | |
print('{:0>2}: "{}"'.format(i, lookup_table[i])) | |
from datetime import datetime as dt | |
print("#"*40) | |
print('current time: ' + str(dt.now())) | |
print('Options: {}'.format(lookup_table[dt.now().hour])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment