-
Notifications
You must be signed in to change notification settings - Fork 0
/
sellerclient.py
240 lines (220 loc) · 11.1 KB
/
sellerclient.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import Pyro4
import Pyro4.errors
import datetime
from prettytable import PrettyTable
# Locate the Pyro4 nameserver and retrieve the remote object using the lookup method
try:
ns = Pyro4.locateNS()
uri = ns.lookup('auction_server')
except Pyro4.errors.NamingError as e:
print(f"{e}: NameServer could not be found")
# Pryo4 proxy object is created using the uri
auction_server = Pyro4.Proxy(uri)
while True:
print('Welcome to BuySell Auctioning System.')
print('1. Create Account')
print('2. Login')
print("")
choice = int(input("Enter your choice: "))
if choice == 1:
try:
# Register as a seller
seller_id = 0
seller_name = input("Enter your business name: ")
seller_number = input("Enter your contact number: ")
password_match = False
while not password_match:
password1 = input("Enter your password:")
password2 = input("Confirm your password:")
if password1 == password2:
seller_password = password2
password_match = True
else:
print("Password does not match. Please try again.")
result = auction_server.create_seller(seller_id, seller_name, seller_number, seller_password)
print(result)
print("")
# Ask user if they want to continue
another_action = input("Do you want to perform another action? (y/n): ")
if another_action.lower() != 'y':
print('Goodbye!')
break
except Exception as e:
print("An error occured: ", e)
elif choice == 2:
try:
# Sign In
seller_name = input("Enter your registered business name: ")
seller_password = input("Enter your password: ")
result = auction_server.signin_seller(seller_name, seller_password)
print("")
print("Login Successful!")
print('ID:', result)
if result != 'Login Failed. Incorrect Name or Password!':
seller_id = result
while True:
print("")
print('1. Create an Auction')
print('2. View all my Auctions')
print('3. View my active Auctions')
print('4. View all the auctions on BuySell')
print('5. View the active auctions on BuySell')
print('6. View the winners of my Auctions')
print(" ")
choice = int(input("Enter your choice: "))
if choice == 1:
def getDate():
current_date = datetime.datetime.now()
minutes = input("Enter the number of minutes: ")
minutes = datetime.timedelta( minutes=int(minutes))
try:
end_date = datetime.datetime.now()+minutes
if end_date < current_date:
print("End time cannot be in the past. Please try again.")
else:
return end_date
except ValueError:
print("Invalid date format. Please try again.")
#sellerObj = (seller_name)
# Prompt for user to enter the file name
itemName = input("Enter the name of the item: ")
stPrice = input("Starting Price: ")
resPrice = input("Reservation Price:")
bid = 0
date = getDate()
auction_server.createAuction(itemName,stPrice, resPrice, seller_id, date)
print("")
# Ask user if they want to continue
another_action = input("Do you want to perform another action? (y/n): ")
if another_action.lower() != 'y':
print('Goodbye!')
break
elif choice == 2:
try:
auctions = auction_server.getSellerAuctions(seller_id)
keys = auctions[0].keys()
keys = list(keys)
keys.remove('seller_id')
# create a prettytable object with the headers as the keys of the dictionaries
table = PrettyTable()
table.field_names = keys
# add the rows to the table
for auction in auctions:
row = [auction[key] for key in keys]
table.add_row(row)
# print the table
print(table)
print("")
except IndexError:
print("You've not created any auctions.")
print("")
# Ask user if they want to continue
another_action = input("Do you want to perform another action? (y/n): ")
if another_action.lower() != 'y':
print('Goodbye!')
break
elif choice == 3:
try:
auctions = auction_server.getSellerActiveAuctions(seller_id)
keys = auctions[0].keys()
keys = list(keys)
keys.remove('seller_id')
# create a prettytable object with the headers as the keys of the dictionaries
table2 = PrettyTable()
table2.field_names = keys
# add the rows to the table
for auction in auctions:
row = [auction[key] for key in keys]
table2.add_row(row)
# print the table
print(table2)
print("")
except IndexError:
print("No Active Auction")
print("")
# Ask user if they want to continue
another_action = input("Do you want to perform another action? (y/n): ")
if another_action.lower() != 'y':
print('Goodbye!')
break
elif choice == 4:
try:
auctions = auction_server.getAuctions()
# create a copy of the dictionary and remove the 'reservationPrice' key
keys = auctions[0].keys()
keys = list(keys)
keys.remove('reservationPrice')
# create a prettytable object with the headers as the keys of the dictionaries
table3 = PrettyTable()
table3.field_names = keys
# add the rows to the table
for auction in auctions:
row = [auction[key] for key in keys]
table3.add_row(row)
# print the table
print(table3)
print("")
except IndexError:
print("No Auction on Buy Sell")
print("")
# Ask user if they want to continue
another_action = input("Do you want to perform another action? (y/n): ")
if another_action.lower() != 'y':
print('Goodbye!')
break
elif choice == 5:
try:
auctions = auction_server.getActiveAuctions()
# create a copy of the dictionary and remove the 'reservationPrice' key
keys = auctions[0].keys()
keys = list(keys)
keys.remove('reservationPrice')
# create a prettytable object with the headers as the keys of the dictionaries
table4 = PrettyTable()
table4.field_names = keys
# add the rows to the table
for auction in auctions:
row = [auction[key] for key in keys]
table4.add_row(row)
# print the table
print(table4)
print("")
except IndexError:
print("No Active Auctions")
print("")
# Ask user if they want to continue
another_action = input("Do you want to perform another action? (y/n): ")
if another_action.lower() != 'y':
print('Goodbye!')
break
elif choice == 6:
try:
auctions = auction_server.getWinnerForSeller(seller_id)
keys = auctions[0].keys()
keys = list(keys)
keys.remove('seller_id')
# create a prettytable object with the headers as the keys of the dictionaries
table5 = PrettyTable()
table5.field_names = keys
# add the rows to the table
for auction in auctions:
row = [auction[key] for key in keys]
table5.add_row(row)
# print the table
print(table5)
print("")
except IndexError:
print("No Winner Yet")
print("")
# Ask user if they want to continue
another_action = input("Do you want to perform another action? (y/n): ")
if another_action.lower() != 'y':
print('Goodbye!')
break
else:
print('Wrong input. Try Again.')
break
except Exception as e:
print("An error occured: ", e)
else:
print('Wrong input. Try Again.')