Instantly share code, notes, and snippets.

# 0atman/departures.py Last active Apr 7, 2019

A simple airport-style departures system. Hacked together in an hour
 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)
Owner Author

### 0atman commented Apr 7, 2019

 `cat requrements.txt` ``````terminaltables colorclass ``````