going-flying.com gemini git repository
51f97c15326b3c50076e93b853b982378b5bbba6 - Matthew Ernisse - 1613855583
add some fucking fancy in our life, eh?
diff --git a/cgi-bin/bofh.py b/cgi-bin/bofh.py index a8c0f8d..6d9e658 100755 --- a/cgi-bin/bofh.py +++ b/cgi-bin/bofh.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 -*- -'''bofh.py (c) 2020 Matthew J Ernisse <matt@going-flying.com> +'''bofh.py (c) 2020 - 2021 Matthew J Ernisse <matt@going-flying.com> All Rights Reserved. Redistribution and use in source and binary forms, @@ -41,9 +41,79 @@ import random import os import sys +TEMPLATE = ''' +# The BOFH Excuse Calendar + +``` + [1;37m[41m╔═════════════════════════════════════════════╗[0m + [1;37m[41m║ The IT professional response of the day ║[0m + [1;37m[41m{}[0m + [1;37m[41m╟─────────────────────────────────────────────╢[0m + ║ ║ + ║ ║ + ║ ║ +{} + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ║ ║ + ╚═════════════════════════════════════════════╝ +``` + +BOFH © Simon Travaglia +=> http://pages.cs.wisc.edu/~ballard/bofh/excuses Excuses List +=> / ↩ Home +''' + + +def date_line(): + vbar = "║" + s = datetime.datetime.utcnow().strftime('%A, %B %m %Y') + pad = int((49 - len(s)) / 2 - 2) + rpad = pad + + if not len(s) % 2: + rpad += 1 + + return f'{vbar}{" " * pad}{s}{" " * rpad}{vbar}' + + +def excuse_line(excuse): + vbar = "║" + + line = [] + lines = [] + out = [] + words = excuse.strip().split() + + while words: + next = words.pop(0) + + if len(' '.join(line)) + len(next) >= 44: + lines.append(' '.join(line)) + line = [] + + line.append(next) + + if line: + lines.append(' '.join(line)) + + for line in lines: + pad = int((49 - len(line)) / 2 - 2) + rpad = pad + + if not len(line) % 2: + rpad += 1 + + out.append(f'\t{vbar}{" " * pad}{line}{" " * rpad}{vbar}') + + return '\n'.join(out) + if __name__ == '__main__': - fn = os.path.dirname(os.environ['SCRIPT_PATH']) + fn = os.path.dirname(os.environ.get('SCRIPT_PATH', '.')) fn = os.path.join(fn, 'excuses') if not os.path.exists(fn): @@ -60,13 +130,9 @@ if __name__ == '__main__': print('*CLICKY* What home directory?') sys.exit() - max = len(excuses) + max = len(excuses) - 1 + excuse = excuses[random.randint(0, max)] print('20 text/gemini\r\n') - print() - print('# The BOFH Excuse Calendar') - print(datetime.datetime.utcnow().strftime('%A, %B %m %Y')) - print(f'> {excuses[random.randint(0, max)]}') - print() - print('BOFH © Simon Travaglia') - print('=> http://pages.cs.wisc.edu/~ballard/bofh/excuses Excuses List') - print('=> / ↩ Home') + date = date_line() + excuse = excuse_line(excuse) + print(TEMPLATE.format(date, excuse))