-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminalInterfaceDatabase.py
More file actions
138 lines (122 loc) · 5.19 KB
/
TerminalInterfaceDatabase.py
File metadata and controls
138 lines (122 loc) · 5.19 KB
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
from BBDatabase import ListingDatabase
from DataStructures.Listings import Listing as Lst
from BBSearch import LstSearch
import os
"""
TO DO:
1. Format "Listing" to accomadate CLI application
2. Finish LstCacheImporter
- Fix UpdateListing to update lisitng based off of unitIndex
- Finish writeListingsToDB
✓3. Add documentation to BBDatabase
"""
def main():
#db = ListingDatabase()
searchFunc = LstSearch()
while True:
os.system("cls")
logo = (
""" ____ _ ____ _
| _ \ | | | _ \ | |
| |_) |_ _| |_ ___| |_) |_ _ _ __ __ _ __ _| | _____ __
| _ <| | | | __/ _ | _ <| | | | '_ \ / _` |/ _` | |/ _ \ \ /\ / /
| |_) | |_| | || __| |_) | |_| | | | | (_| | (_| | | (_) \ V V /
|____/ \__, |\__\___|____/ \__,_|_| |_|\__, |\__,_|_|\___/ \_/\_/
__/ | __/ |
|___/ |___/ """
)
print(f"{'─'*80}")
print(logo)
print(f"{'─'*80}")
print("\tWelcome to the database interface!",
"\nBelow is where your active search parameters are displayed. Please select from the provided menu to filter your results.\n",
"\n\tWhat would you like to do?")
print(f"{'─'*80}")
print(f"\t Search Parameters:\n\t\tFavorited: {searchFunc.favorited} \n\t\tMin Rent: {searchFunc.minRent} \n\t\tMax Rent: {searchFunc.maxRent} \n\t\tRooms: {searchFunc.numRooms} \n\t\tUtilities: {searchFunc.utilsIncluded} \n\t\tHost Site: {searchFunc.hostSite}")
print(f"{'─'*80}")
print(""" Menu:
1. Set Favorited
2. Set Rent Range
3. Set Rooms
4. Set Utilities
5. Set Host Site
7. Get Results
8. Sort Results (asc)
9. Sort Results (desc)
10. Clear Settings
0. Exit
""")
while True:
choice = input("Input: ")
try:
choice = int(choice)
break
except:
print("Input must be a number")
match choice:
case 1: # Toggle favorited
searchFunc.setIsFavorited(not searchFunc.favorited)
case 2: # Set rent
minRent = float(input("Min Rent: "))
maxRent = float(input("Max Rent: "))
searchFunc.setRent(minRent, maxRent)
case 3: # Set rooms
rooms = int(input("Rooms: "))
searchFunc.setRooms(rooms)
case 4: # Set utilities
searchFunc.setUtilities(not searchFunc.utilsIncluded)
case 5: # Set host site
hostSite = input("Host Site: ")
searchFunc.setHostSite(hostSite)
case 7: # Get results
searchFunc.getResults()
print(f"\n\n\n{'─'*80}\n Sorted Listings:\n")
print(f" ID {'Listing Name':<25}{'Rent':<11}Rooms Utils Host Site {'Address':<40} URL Notes \n{'─'*80}")
for listing in searchFunc.tempList:
print(listing)
print(f"\n{'─'*80}")
input("Press ENTER to continue")
case 8: # Sort (asc)
searchFunc.criteria = None
searchFunc.order = None
while True:
try:
category = input("Category (1. for rent, 2. for rooms, 0. to exit): ")
category = int(category)
if category == 0:
break
elif category == 1:
category = "rent"
elif category == 2:
category = "rooms"
searchFunc.sortResults(category, "asc")
break
except:
print("Input must be 1, 2 or 0\n")
category = None
case 9: # Sort (desc)
searchFunc.criteria = None
searchFunc.order = None
while True:
try:
category = input("Category (1. for rent, 2. for rooms, 0. to exit): ")
category = int(category)
if category == 0:
break
elif category == 1:
searchFunc.sortResults("rent", "desc")
elif category == 2:
searchFunc.sortResults("rooms", "desc")
break
except:
print("Input must be 1, 2 or 0\n")
case 10: # Clear settings
searchFunc.clearSettings()
case 0: # Exit
break
case _: # Default
print("Invalid Input")
input("Press ENTER to continue")
#db.close()
if __name__ == "__main__":
main()