Last active
April 7, 2019 12:04
-
-
Save 0atman/dbb739bd0f411b312a93b07aae1eb33d to your computer and use it in GitHub Desktop.
A simple airport-style departures system. Hacked together in an hour
This file contains 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
import os | |
import time | |
import datetime | |
from datetime import timedelta | |
from terminaltables import SingleTable | |
from colorclass import Color | |
FIVE_MINS = timedelta(minutes=5) | |
def t(h, m): | |
""" | |
Convert hours and minutes to today, at that time. | |
""" | |
now = datetime.datetime.now() | |
return datetime.datetime(now.year, now.month, now.day, h, m) | |
def GREEN(text): | |
return Color('{autobggreen}{autowhite}%s{/black}{/bggreen} ' % text) | |
def RED(text): | |
return Color('{autobgred}{autowhite}%s{/black}{/bgred} ' % text) | |
def gate(h, m): | |
""" | |
Returns a tuple of (time, gate_status) | |
""" | |
departure = t(h, m) | |
departure_minus_five = departure - FIVE_MINS | |
if departure_minus_five > datetime.datetime.now(): | |
status = 'ON TIME' | |
elif departure < datetime.datetime.now(): | |
status = RED('CLOSED') | |
else: | |
status = GREEN('GO TO GATE') | |
return [departure.time(), status] | |
def table(): | |
table_data = [ | |
['Departure', 'Gate Status', 'Departure', 'Gate Status'], | |
gate(19, 30) + gate(21, 10), | |
gate(19, 40) + gate(21, 20), | |
gate(19, 50) + gate(21, 30), | |
gate(20, 00) + gate(21, 40), | |
gate(20, 10) + gate(21, 50), | |
gate(20, 20) + gate(22, 00), | |
gate(20, 30) + gate(22, 10), | |
gate(20, 40) + gate(22, 20), | |
gate(20, 50) + gate(22, 30), | |
gate(21, 00) + gate(22, 40), | |
] | |
return SingleTable(table_data).table | |
while True: | |
os.system('clear') | |
print('Current Time: ', datetime.datetime.now().time()) | |
print(table(), end='') | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cat requrements.txt