-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.py
More file actions
310 lines (251 loc) · 9.07 KB
/
library.py
File metadata and controls
310 lines (251 loc) · 9.07 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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import re #re=regular expression
import mysql_connection as conn
import getpass
import sys
def card_validation(s)->bool:
lst:list = s.split("-")
if len(lst)==4:
for ch in lst:
if len(ch)!=4:
return False
else:
return False
p = re.search("[456][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]",s)
if p==None:
return False
else:
return True
#5412-8750-2248-9156
def Input_card_num()->str:
print("Valid card number format xxxx-xxxx-xxxx-xxxx.")
print("The first character must be either 4,5 or 6. Ex. 4xxx-xxxx-xxxx-xxxx.")
msg="Enter the card number to pay: "
while(1):
num=input(msg)
if num=='':
return ""
elif card_validation(num)==True:
return num
else:
msg="Invalid card number. Enter again: "
def date_validation(date_string)->bool:
import datetime
#date_string = '2017-12-31'
date_format = '%Y-%m-%d'
try:
dateObject = datetime.datetime.strptime(date_string, date_format)
return True
except ValueError:
print("Incorrect data format, should be YYYY-MM-DD")
return False
def input_date(msg=None)->str:
if msg==None:
msg="Enter the date(YYYY-MM-DD): "
while(1):
date=input(msg)
if date=='':
return ""
elif(date_validation(date))==True:
return date
break
def input_text(msg: str, maxlength: int)->str:
while True:
name=input(msg)
if name=="":
return ""
elif (len(name))>maxlength:
print("Input data length is ",len(name),". It's length cannot more than ",maxlength)
else:
return name
def number_validation(numb)->bool:
p=re.search("^\\+?[1-9][0-9]{9,11}$",numb)
if p==None:
return False
else:
return True
#91345647583
def number_input()->str:
msg="Enter the phone number: "
while True:
numb=input(msg)
if numb=="":
return ""
elif (number_validation(numb))==True:
return numb
else:
msg="Invalid phone number. Enter again: "
def check_int(num)->bool:
for char in num:
if ord(char)>32 and ord(char)<48 or ord(char)>57 and ord(char)<65 or ord(char)>90 and ord(char)<97 or ord(char)>122 and ord(char)<127:
return False
if len(num)>9:
return False
else:
p=re.search("^[0-9 \-]+$", num)
if p==None:
return False
else:
return True
def input_int(msg)->int:
while True:
num=input(msg)
if num=="":
return 0
elif check_int(num)==True:
if int(num)<0:
msg="Input cannot be negative. Enter again: "
else:
return int(num)
else:
msg="Invalid input. Expected integer value. Enter again: "
def input_Sid()->int:
while True:
sid=input_int("Enter the sell id: ")
if sid==0:
return 0
if conn.is_sell_exist(sid)>0:
return sid
else:
print("Invalid Sell id. Existing Sell Ids are: ",conn.get_sell_ids())
def input_Bid()->int:
while True:
bid=input_int("Enter the Bid id: ")
if bid==0:
return 0
if conn.is_bid_exist(bid)>0:
return bid
else:
print("Invalid Bid id")
def input_user()->str:
while True:
uid=input_text("Enter the user id: ",20)
if uid=="":
return ""
elif conn.is_user_exist(uid)>0:
return uid
else:
print("Invalid Uid id. Existig User Ids are: ",conn.get_user_ids())
def input_Product()->str:
while True:
pid=input_text("Enter the Pid id: ",20)
if pid=="":
return ""
elif conn.is_pid_exist(pid)>0:
return pid
else:
print("Invalid Pid id. Existing Product ids are: ",conn.get_product_ids())
def input_new_sid()->int:
while True:
sid=input_int("Enter the sell id: ")
if sid==0:
return 0
if conn.is_sell_exist(sid)>0:
print("Given sell id already exist. Existing Sell Ids are: ",conn.get_sell_ids())
else:
return sid
def input_new_pid()->str:
while True:
pid=input_text("Enter the product id: ",20)
if pid=="":
return ""
if conn.is_pid_exist(pid)>0:
print("Given product id already exist. Existing Product Ids are: ",conn.get_product_ids())
else:
return pid
def is_buyer_seller()->str:
while True:
Utype=input_text("Enter whether you are a buyer or a seller (B/S): ",1)
if Utype=="":
return ""
elif Utype=="B" or Utype=="b" or Utype=="S" or Utype=="s":
return Utype
else:
print("invalid Input. Enter again.")
def input_new_user()->str:
while True:
uid=input_text("Enter your User Id: ",20)
if uid=="":
return ""
if uid=="NUL":
print("Invalid user id.")
elif conn.check_user_exist(uid)==0:
return uid
def format_cardno(cardno)->str:
formated_cardno=""
i=0
for ch in cardno:
formated_cardno += ch
i=i+1
if i % 4 == 0 and i<16:
formated_cardno = formated_cardno + "-"
return formated_cardno
def yes_no_menu()->int:
print("1.Yes\n2.No")
while True:
ch=int(input_int("Enter your choice: "))
if ch==1:
return 1
elif ch==2:
return 2
def pay_cancel_menu()->int:
print("\n1)Pay\n2)Cancel")
while True:
ch=int(input_int("Enter your choice: "))
if ch==1:
return 1
elif ch==2:
return 2
def security_fee(offer:int, msg:str)->int:
while True:
fee=input_int(msg)
if fee==0:
return 0
elif fee>=offer:
print("Security fees cannot be greater than or equal to the offer price [",offer,"]. Enter again: ")
else:
return fee
def help_box():
print("\n---------------------------------------------------Help-----------------------------------------------------------------")
print(" 1. During Add, Edit, Delete or Update Sales, User, Item and Bid, press key 'Enter' to exit.")
print(" 2. If the program runs through DOS(cmd.exe) input password characters will be hidden else the password character will be shown.")
print(" 3. This program alows to register and login user. ")
print(" 4. User type can be as S/B where S is a seller and B is a buyer.")
print(" 5. After login user can add edit and delete Item.")
print(" 6. After creating item details one can sell the item by adding the records in sales.")
print(" 7. This program also allows to add, edit and delete sale records. ")
print(" 8. During add sale, seller can also mention security money.")
print(" 9. Aftr adding sales the buyer can purchase an item after placing their bids.")
print(" 10. During add bid he can enter the price at which he want to purchase it.")
print(" 11. During add bid the buyer will have to pay if particular sale require security money. ")
print(" 12. After adding bid, the seller can finalise the added bids for his sales.")
print(" 13. Once the bid is finalise, the buyer can make the payment for his bids. ")
print(" 14. Once the payment is done the item will be delivered at his address.")
print(" 15. This program will accept the money only through debit/credit card.")
print(" 16. Valid card number must beging with either 4,5 or 6.")
print(" 17. Valid card format is xxxx-xxxx-xxxx-xxxx where x is the numeric value.")
print(" 18. Valid date format is YYYY-MM-DD.")
print(" 19. Special characters are not allowed.")
print("\n---------------------------------------------------End------------------------------------------------------------------\n")
def get_password()->str:
try:
p = getpass.getpass("Password :")
return p
except Exception as error :
print("get_password error :", error)
return password
def get_new_password()->str:
while True:
try:
p = getpass.getpass("Password :")
if p=="":
return ""
p2 = getpass.getpass("Re Enter Password :")
if p2=="":
return ""
if p==p2:
return p
else:
print("Password and Re Enter password does not match. Enter again.")
except Exception as error :
password=input_text("Enter your password: ",25)
return password