· 8 years ago · Aug 27, 2018, 07:08 PM
1import csv
2import sqlite3
3from colorama import init
4from colorama import Fore, Back, Style
5init()
6
7db = sqlite3.connect('floorlocation.db')
8cursor = db.cursor()
9cursor.execute('''
10 CREATE TABLE IF NOT EXISTS moves (
11 bin1 INTEGER, bin2 INTEGER, bin3 INTEGER, bin4 INTEGER, bin5 INTEGER, bin6 INTEGER, source TEXT, destination TEXT)
12''')
13title = """
14 /$$ /$$ /$$
15| $$ /$ | $$ | $$
16| $$ /$$$| $$ /$$$$$$ | $$ /$$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$
17| $$/$$ $$ $$ /$$__ $$| $$ /$$_____/ /$$__ $$| $$_ $$_ $$ /$$__ $$
18| $$$$_ $$$$| $$$$$$$$| $$| $$ | $$ \ $$| $$ \ $$ \ $$| $$$$$$$$
19| $$$/ \ $$$| $$_____/| $$| $$ | $$ | $$| $$ | $$ | $$| $$_____/
20| $$/ \ $$| $$$$$$$| $$| $$$$$$$| $$$$$$/| $$ | $$ | $$| $$$$$$$
21|__/ \__/ \_______/|__/ \_______/ \______/ |__/ |__/ |__/ \_______/
22 """
23mainInput = ""
24bins = []
25sourceLocation = ""
26destinationLocation = ""
27tempString = ""
28locationWords = ["*","FLC"]
29binPop = ""
30
31#COMMANDS
32removeBin = "REMOVELASTBIN"
33removeSource = "REMOVESOURCE"
34removeLastLine = "REMOVELAST"
35clearInput = "CLEARINPUT"
36startOver = "STARTOVER"
37
38print(Fore.GREEN + title + Style.RESET_ALL)
39def mainFunction():
40 global mainInput
41 global bins
42 global sourceLocation
43 global destinationLocation
44 global tempString
45 if (not sourceLocation):
46 mainInput = input(Fore.BLUE + Style.BRIGHT + "Please scan the source floor location or your bins: \n" + Style.RESET_ALL)
47 else:
48 mainInput = input(Fore.BLUE + Style.BRIGHT + "Please scan the destination floor location or your bins: \n" + Style.RESET_ALL)
49 if (removeBin in mainInput):
50 if (bins):
51 bins.pop()
52 tempString = ""
53 for x in range(len(bins)):
54 tempString += (bins[x] + ",")
55 if (not bins):
56 print(Fore.YELLOW + Style.BRIGHT + "Bins is now empty")
57 else:
58 print(Fore.GREEN + Style.BRIGHT + tempString)
59 else:
60 print(Fore.RED + Style.BRIGHT + "No bins have been scanned yet!")
61 mainFunction()
62 elif (removeSource in mainInput):
63 sourceLocation = ""
64 print(Fore.YELLOW + Style.BRIGHT + "Source location has been reset")
65 mainFunction()
66 elif (removeLastLine in mainInput):
67 removeLastLineSQL()
68 mainFunction()
69 elif (clearInput in mainInput):
70 mainInput = ""
71 print(Fore.YELLOW + Style.BRIGHT + "You just cleared the input")
72 mainFunction()
73 elif (startOver in mainInput):
74 bins[:] = []
75 sourceLocation = ""
76 destinationLocation = ""
77 print(Fore.YELLOW + Style.BRIGHT + "You just cleared the current session")
78 mainFunction()
79 elif not any(word in mainInput for word in locationWords):
80 if (not mainInput):
81 mainFunction()
82 elif (mainInput in bins):
83 print(Fore.RED + Style.BRIGHT + "That bin already has been scanned!")
84 mainFunction()
85 else:
86 if len(bins) == 6:
87 print(Fore.RED + Style.BRIGHT + "You are carrying to many bins, please scan your source and destination location" + Style.RESET_ALL)
88 mainFunction()
89 else:
90 bins.append(mainInput)
91 tempString = ""
92 for x in range(len(bins)):
93 tempString += (bins[x] + ",")
94 print(Fore.GREEN + Style.BRIGHT + tempString)
95 mainFunction()
96 elif (not sourceLocation):
97 sourceLocation = "S" + mainInput
98 print (Fore.GREEN + Style.BRIGHT + "Source location is: " + sourceLocation + Style.RESET_ALL)
99 mainFunction()
100 elif (not bins):
101 print(Fore.YELLOW + Style.BRIGHT + "Please scan bins before scanning your destination floor location!")
102 mainFunction()
103 elif (sourceLocation == "S" + mainInput):
104 print(Fore.RED + Style.BRIGHT + "Your source and destination cannot be the same!")
105 mainFunction()
106 else:
107 destinationLocation = "E" + mainInput
108 print (Fore.GREEN + Style.BRIGHT + tempString + " moved from " + sourceLocation + " to " + destinationLocation)
109 sendToSQL()
110 mainInput = ""
111 bins = []
112 sourceLocation = ""
113 destinationLocation = ""
114 tempString = ""
115 mainFunction()
116def sendToSQL():
117 total = len(bins) + 2
118 max = 8
119 if total < max:
120 while total < max:
121 bins.append('')
122 total = total + 1
123 bins.append(sourceLocation)
124 bins.append(destinationLocation)
125 cursor.execute('INSERT INTO moves(bin1,bin2,bin3,bin4,bin5,bin6,source,destination) VALUES(?,?,?,?,?,?,?,?)',bins)
126 db.commit()
127def removeLastLineSQL():
128 cursor.execute('DELETE FROM moves WHERE rowid = (SELECT MAX(rowid) FROM moves);')
129 db.commit()
130 print(Fore.YELLOW + Style.BRIGHT + "Your previous entry has been removed!" + Style.RESET_ALL)
131def sendToCSV():
132 with open('moves.csv', 'a') as csvfile:
133 csvWriter = csv.writer(csvfile, delimiter=',')
134 total = len(bins) + 2
135 max = 8
136 if total < max:
137 while total < max:
138 bins.append('')
139 total = total + 1
140 bins.append(sourceLocation)
141 bins.append(destinationLocation)
142 csvWriter.writerow(bins)
143try:
144 mainFunction()
145except KeyboardInterrupt:
146 print(Fore.RED + """
147 /$$$$$$ /$$ /$$ /$$
148 /$$__ $$ | $$| $$ | $$
149| $$ \__/ /$$$$$$ /$$$$$$ /$$$$$$$| $$$$$$$ /$$ /$$ /$$$$$$ | $$
150| $$ /$$$$ /$$__ $$ /$$__ $$ /$$__ $$| $$__ $$| $$ | $$ /$$__ $$| $$
151| $$|_ $$| $$ \ $$| $$ \ $$| $$ | $$| $$ \ $$| $$ | $$| $$$$$$$$|__/
152| $$ \ $$| $$ | $$| $$ | $$| $$ | $$| $$ | $$| $$ | $$| $$_____/
153| $$$$$$/| $$$$$$/| $$$$$$/| $$$$$$$| $$$$$$$/| $$$$$$$| $$$$$$$ /$$
154 \______/ \______/ \______/ \_______/|_______/ \____ $$ \_______/|__/
155 /$$ | $$
156 | $$$$$$/
157 \______/
158 """ + Style.RESET_ALL)