From 0b2b39bb88735f5219913a1350642a0d4f6af4c5 Mon Sep 17 00:00:00 2001 From: Jaculabilis Date: Wed, 10 Jan 2018 01:36:32 -0600 Subject: [PATCH] Added skeleton REPL --- validate.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 validate.py diff --git a/validate.py b/validate.py new file mode 100644 index 0000000..64b953c --- /dev/null +++ b/validate.py @@ -0,0 +1,39 @@ +#!/usr/bin/python + +import sys +from datetime import datetime + +def timestamped(s): + """ + Prepends a timestamp to a string. + """ + return "[{:%Y-%m-%d %H:%M:%S}] {}".format(datetime.now(), s) + +def read_loop(): + """ + Simple REPL skeleton for validating scanned IDs. + """ + # Open the log file in append mode + log_file = open("./access.log", "a") + log_file.write(timestamped("=== Door security initiated ===\n")) + + # Begin the loop + while True: + # TODO: Read in the ID + + # TODO: Check if the ID is authorized + authorized = False + + # If the user is not authorized, deny access + if input not in authorized: + s = timestamped("##### denied\n") + log_file.write(s) + # If the user is authorized, perform the unlock procedure + else: + s = timestamped("##### validated") + log_file.write(s) + # TODO: Play open tone + # TODO: Run unlock procedure + +if __name__ == "__main__": + read_loop()