-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
94 lines (74 loc) · 2.38 KB
/
main.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
# Python Script that lets APSC100 Group Members enter building data into our instance of MongoDB
# Uses a general building schema
# Print Welcome
# Imports
import getpass
import login as LoginClient
import entry as EntryClient
import gen as QRClient
import selector as SelectionTool
print("Welcome to the QueensQR Data Entry Utility")
print("Please Login")
# Login database user
usr = input("username: ")
try:
pwd = getpass.getpass("password: ")
print("\n")
mongo = LoginClient.auth(usr, pwd)
except Exception as err:
print("Login Error", err)
else:
pass
print(mongo)
print("\n")
print("Logged in")
# Get DB object and collection of buildings
db = mongo.apscm3
collection = db.buildings
print(db)
print(collection)
print("\nData Retreived")
# Prompt User
print("Please Select an Action (Enter the number corresponding to the action)\n")
print("(1) List all buildings\n")
print("(2) Enter data for a new building\n")
print("(3) Generate a QR Code image for a certain building\n")
print("(4) Upload Floorplans for a Building\n")
ans = input("answer: ")
# collect all building objects in array
buildings = list(collection.find({}))
if ans == "1":
for i, b in enumerate(buildings):
print("\n-------------------------\n")
print("index = " + str(i) + "\n")
print(b)
print("\n-------------------------\n")
elif ans == "2":
try:
objectId = collection.insert_one(EntryClient.newBuilding()).inserted_id
print("Object Placed in DB under ID: " + str(objectId))
except Exception as err:
print("Failed to insert object into DB", err)
else:
pass
# Prompt if user would like to generate QR code using that object id
ans = int(input("entrance index: "))
QRClient.generate(objectId, ans)
exit()
elif ans == "3":
selection = SelectionTool.selectFrom(buildings)
print("You Have Selected " + selection['name'] + "\nGenerate a QR Code?")
ans = input("answer [y/n] ")
if (ans == 'y'):
ans = int(input("entrance index: "))
QRClient.generate(selection['_id'], ans)
elif (ans == 'n'):
exit()
else:
print("Enter a valid input")
exit()
elif ans == "4":
selection = SelectionTool.selectFrom(buildings)
EntryClient.newFloorPlan(selection['_id'])
pass
exit()