-
Notifications
You must be signed in to change notification settings - Fork 0
/
ETHAN.py
181 lines (142 loc) · 7.28 KB
/
ETHAN.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import pickle
from difflib import get_close_matches
import os
# load the saved inventory from the file to a dictionary
inventory = pickle.load(open('DO_NOT_TOUCH_INVENTORY.txt', 'rb'))
def item_search(item):
if item in inventory:
# if the name was exact, just print the thing and location
print("The location of " + item + " is " + inventory[item])
else:
# create a list of keys
keys = list(inventory.keys())
# this finds up the three best matches for the search item in keys
best_matches = get_close_matches(item, keys, 3, 0.5)
if len(best_matches) > 0:
# print out locations of best matches if there were any
for guess in best_matches:
item_search(guess)
else:
# say we couldn't find anything
print("Couldn't find anything matching the name '" + item + "'. Try another name or add that item")
def fixtures(entered):
try:
# open the info file with the default system program, if it exists
os.startfile("W:\\WDS\\Inventory\\fixture-docs\\" + entered + ".docx")
except FileNotFoundError:
# create a new document
print("That fixture number doesn't exist, either add it or try again")
def items(entered):
# if the user entered "add"
if (entered == "add" or entered == "a"):
# get more responses to add to the dictionary
name = str(input("Enter the name of the item to add ")).lower()
if (name != "exit"):
location = str(input("Enter the location of the item (room.storage.row.description): ")).lower()
if (location != "exit"):
# add the new item
inventory[name] = location
elif (entered == "print" or entered == "p"):
# this just displays everything in the inventory
print(inventory)
elif (entered == "delete" or entered == "d"):
# get the name of the item and make it lowercase
name = str(input("Enter the name of the item to delete ")).lower()
if name in inventory:
# delete from the dictionary inventory the item with that name
entered = str(input("Confirm that you want to delete %s \n"
"THIS CANNOT BE UNDONE (Y/N): " % (name, ))).lower()
if (entered == "y"):
del(inventory[name])
print("\n%s has been deleted" % (name, ))
else:
print("Hey you can't delete something that doesn't exist! That's like dividing 0 by 0!")
elif (entered == "change" or entered == "c"):
name = str(input("Enter the name of the item to change ")).lower()
if name in inventory:
location = str(input("Enter the new location of " + name + ": ")).lower()
inventory[name] = location
else:
# create a list of keys
keys = list(inventory.keys())
# this finds up the three best matches for the search item in keys
best_matches = get_close_matches(name, keys)
if (len(best_matches) > 0):
print("Couldn't find that, add an item, or try one of these: ")
print(best_matches)
else:
print("Couldn't find that, add an item, or try again")
elif (entered == "open the pod bay doors, hal"):
# just having some fun
print("I'm sorry Dave, I'm afraid I can't do that")
elif (entered == "is this loss?"):
# more fun
print("|\t||\n||\t|_")
elif (entered == "people sometimes make mistakes."):
# Okay okay, last one I promise
entered = str(input("\nYES THEY DO. SHALL WE PLAY A GAME?\n\n"))
if (entered == "Love to. How about Global Thermonuclear War?"):
print("\nWOULDN'T YOU PREFER A GOOD GAME OF CHESS?")
else:
# in this case, we are searching for an item, look it up in function
item_search(entered)
# runs every loop
pickle.dump(inventory, open("DO_NOT_TOUCH_INVENTORY.txt", "wb"))
def halp():
# named this way because help() is already a python thing
topic = str(input("""\nWhat topic do you want help with? \
(add, change, delete, print, search, fixtures) or exit """)).lower()
while (topic != "exit"):
if (topic == "add" or topic == "a"):
print("""To add a new item, enter 'add' or 'a'. \
You will then be prompted for the name of the item and then the location""")
print("Here are the rooms for locations: shop, wash, CMM, closet, office, MRB")
elif (topic == "change" or topic == "c"):
print("To change an existing item, enter 'change' or 'c'. You will then be prompted"
" for the name of the item then the new location")
elif (topic == "delete" or topic == "d"):
print("To delete an existing item, enter 'delete' or 'd'. You will then be prompted"
" for the name of the item. WARNING: this is irreversable, there is no undo")
elif (topic == "print" or topic == "p"):
print("This displays the entirety of the inventory on the screen.")
elif (topic == "search" or topic == "s"):
print("To search for an item, just enter its name. If that exact name doesn't exist,"
" the system will show the 3 best matches and their locations")
elif (topic == "fixtures" or topic == "f"):
print("To do stuff with fixtures, enter the fixture number with an exclamation mark in front"
" (ex. !9999)\nIt will automatically search for the file and display it if it exists")
else:
print("I-I-I-I-I'll do almost anything. That you want me toooo. But I can't go for that, no can do")
topic = str(input("\nWhat topic do you want help with? "
"(add, change, delete, print, search, fixtures) or exit ")).lower()
def main():
# License agreement
print("NOTICE: By using this software you are agreeing to the terms and conditions listed in LICENSE.")
# initial input
entered = str(input("Options: \nhelp\tadd\tchange\ndelete\tprint\texit\nOr just enter the name"
" of the item to find (for fixtures enter ! then the number ex. !9999) ")).lower()
while (entered != "exit"):
if (entered == "help"):
halp()
elif (entered[:1] == "!"):
# call the fixtures program with everthing but the !
fixtures(entered[1:])
elif (entered == "about"):
print("""
______ _______ _ _ _ _
| ____|__ __| | | | /\ | \ | |
| |__ | | | |__| | / \ | \| |
| __| | | | __ | / /\ \ | . ` |
| |____ | | | | | |/ ____ \| |\ |
|______| |_| |_| |_/_/ \_\_| \_|
Everything Those Humans Are Needing
Created by Ethan Hansen
rev 1.6.1
8-11-2018
""")
else:
# call the items function with the input
items(entered)
entered = str(input("\nOptions: \nhelp\tadd\tchange\ndelete\tprint\texit\nOr just enter the name of the item"
" to find (for fixtures enter ! then the number ex. !9999) ")).lower()
main()