#! python3 # -*- coding: utf-8 -*- """ Created on Thu Jun 20 15:23:05 2019 @author: mor96805 Make sure to add bat file and the bat file's path to the environment variable Tracks the door bell calls in a csv format The csv will take the following format Date, Time, Weekday, Buzzer (YN), Door (YN), Delivery (YN), BV Glasgow Employee (YN), Non-Rory Event (YN) """ import sys import datetime stamp = datetime.datetime.now() date_stamp = str(stamp.strftime("%d/%m/%Y")) time_stamp = str(stamp.strftime("%H:%M:%S")) wd = str(datetime.datetime.today().weekday()) scenarios = {"a":"1,0,0,0,0", "b":"0,1,0,0,0", "c":"1,1,0,0,0", \ "d":"1,0,1,0,0", "e" : "0,1,1,0,0", "f" : "1,1,1,0,0", \ "g" : "1,0,0,1,0", "h" : "0,1,0,1,0", "i" : "1,1,0,1,0", \ "x":"0,0,0,0,0", \ "k":"1,0,0,0,1", "l":"0,1,0,0,1", "m":"1,1,0,0,1", \ "n":"1,0,1,0,1", "o" : "0,1,1,0,1", "p" : "1,1,1,0,1", \ "q" : "1,0,0,1,1", "r" : "0,1,0,1,1", "s" : "1,1,0,1,1", \ "t":"0,0,0,0,1"} designated_csv = 'C:\\Users\\PATH TO YOUR CSV HERE!\\door_tracker.csv' if len(sys.argv) == 2: key = str(sys.argv[1]) scen = scenarios[key] line = ','.join([date_stamp, time_stamp, wd, scen]) print() print("Data entry:") print("date, time, weekday, Buzzer (YN), Door (YN), Delivery (YN), BV Glasgow, Non-Rory") print(line) print() ans = input("Enter into csv? (Y, or any other key for no): ") if ans.upper() == "Y": print('Writing to csv') try: f = open(designated_csv, 'a') f.write('\n' + line) f.close() print('Written to CSV') except: print('Failed to write to CSV') else: sys.exit() else: print("no arguments given") print() print("| # | Buzzer (YN) | Door (YN) | Delivery (YN) | BV Glasgow | Non-Rory |") print("|----------------------------------------------------------------------|") print("| a | 'y, | n, | n, | n' | n | # buzzer alone") print("| b | 'n, | y, | n, | n' | n | # door alone") print("| c | 'y, | y, | n, | n' | n | # buzzer and door") print("| d | 'y, | n, | y, | n' | n | # buzzer only delivery") print("| e | 'n, | y, | y, | n' | n | # door only delivery") print("| f | 'y, | y, | y, | n' | n | # door and buzzer delivery") print("| g | 'y, | n, | n, | y' | n | # buzzer only BV") print("| h | 'n, | y, | n, | y' | n | # door only BV") print("| i | 'y, | y, | n, | y' | n | # buzzer and door BV") print("| x | 'n, | n, | n, | n' | n | # No door events today for Rory") print("| | | | | | | ") print("| k | 'y, | n, | n, | n' | y | # Non-Rory buzzer alone") print("| l | 'n, | y, | n, | n' | y | # Non-Rory door alone") print("| m | 'y, | y, | n, | n' | y | # Non-Rory buzzer and door") print("| n | 'y, | n, | y, | n' | y | # Non-Rory buzzer only delivery") print("| o | 'n, | y, | y, | n' | y | # Non-Rory door only delivery") print("| p | 'y, | y, | y, | n' | y | # Non-Rory door and buzzer delivery") print("| q | 'y, | n, | n, | y' | y | # Non-Rory buzzer only BV") print("| r | 'n, | y, | n, | y' | y | # Non-Rory door only BV") print("| s | 'y, | y, | n, | y' | y | # Non-Rory buzzer and door BV") print("| t | 'n, | n, | n, | n' | y | # Non-Rory No door events today") print("|----------------------------------------------------------------------|") desc = {'a':"buzzer alone", 'b':"door alone", 'c':"buzzer and door", 'd':"buzzer only delivery", \ 'e':"door only delivery", 'f':"door and buzzer delivery", 'g':"buzzer only BV", \ 'h':"door only BV", 'i':"buzzer and door BV", 'x':"No door events today", \ 'y1':'Non-Rory buzzer only', 'y2':'Non-Rory door only', 'y3':'Non-Rory door and buzzer',} print() key = input("Give me the key: ") while key not in scenarios: key = str(input('try again, "stop" to quit: ')) if key == "stop": break scen = scenarios[key] print() #print(desc[key]) print(key + " = " + str(scen)) line = ','.join([date_stamp, time_stamp, wd, scen]) print() print("Data entry:") print("date, time, weekday, Buzzer (YN), Door (YN), Delivery (YN), BV Glasgow, Non-Rory") print(line) ans = input("Enter into csv? (Y, or any other key for no): ") if ans.upper() == "Y": print('Writing to csv') try: designated_csv = 'C:\\Users\\PATH TO YOUR CSV HERE\\door_tracker.csv' f = open(designated_csv, 'a') f.write('\n' + line) f.close() print('Written to CSV') except: print('Failed to write to CSV') else: sys.exit()