1+ import pickle
2+ from datetime import date
3+
4+ import mysql .connector
5+
6+
7+ def age (birthdate ):
8+ today = date .today ()
9+ age = today .year - birthdate .year - ((today .month , today .day ) < (birthdate .month , birthdate .day ))
10+ return age
11+
12+ def ap1 ():
13+ cred = open ("cred.dat" ,"rb" )
14+ dat = pickle .load (cred )
15+ cred .close ()
16+ Passwo = dat [0 ]
17+ Databa = dat [1 ]
18+ query = mysql .connector .connect (host = "localhost" ,user = "root" ,password = Passwo ,database = Databa )
19+ cur = query .cursor ()
20+ print ("-------------Create account Process-------------" )
21+
22+ #client number
23+ while True :
24+ acc_no = input ("Enter acc_no (max 5 int): " )
25+ if len (acc_no ) <= 5 :
26+ try :
27+ acc_no = int (acc_no )
28+ print ("Done OK" )
29+ except ValueError :
30+ print ("acc_no should be an integer!!" )
31+ else :
32+ break
33+ else :
34+ print ("Maximum length is 5!" )
35+ #client Birth date
36+ while True :
37+ while True :
38+ year = input ("Enter birth year (4 int): " )
39+ if len (year ) == 4 :
40+ try :
41+ year = int (year )
42+ print ("Done OK" )
43+ except ValueError :
44+ print ("year should be an integer!!" )
45+ else :
46+ break
47+ else :
48+ print ("Year consists of 4 integers!!" )
49+
50+ while True :
51+ month = input ("Enter birth month (2 int) (01 to 12): " )
52+ if len (month ) == 2 :
53+ try :
54+ month = int (month )
55+ print ("Done OK" )
56+ except ValueError :
57+ print ("month should be an integer!!" )
58+ else :
59+ break
60+ else :
61+ print ("Month consists of 2 integers!!" )
62+
63+ while True :
64+ day = input ("Enter birth day (2 int) : " )
65+ if len (day ) == 2 :
66+ try :
67+ day = int (day )
68+ print ("Done OK" )
69+ except ValueError :
70+ print ("Date should be an integer!!" )
71+ else :
72+ break
73+ else :
74+ print ("Date consists of 2 integers!!" )
75+
76+ try :
77+ birth_date = date (year ,month ,day )
78+ except ValueError :
79+ import traceback
80+ traceback .print_exc ()
81+ else :
82+ if age (birth_date )>= 10 :
83+ break
84+ else :
85+ print ("Account holder must be atleast 10 years of age!!" )
86+ #client name
87+ while True :
88+ first_name = input ("Enter first name (max 15 char): " )
89+ if len (first_name )<= 15 :
90+ break
91+ else :
92+ print ("Max 15 characters" )
93+
94+ while True :
95+ last_name = input ("Enter last name (max 15 char): " )
96+ if len (last_name )<= 15 :
97+ break
98+ else :
99+ print ("Max 15 characters" )
100+ #client Gender
101+ while True :
102+ print ("1.Male" )
103+ print ("2.Female" )
104+ a = input ("Enter choice (1 or 2):" )
105+ if a == '1' :
106+ gender = 'M'
107+ break
108+ elif a == '2' :
109+ gender = 'F'
110+ break
111+ else :
112+ print ("Wrong input!!" )
113+
114+ #client Account Type
115+ while True :
116+ print ("1.Savings account" )
117+ print ("2.Current account" )
118+ a = input ("Enter choice (1 or 2):" )
119+ if a == '1' :
120+ acc_type = 'S'
121+ break
122+ elif a == '2' :
123+ acc_type = 'C'
124+ break
125+ else :
126+ print ("Wrong input!!" )
127+
128+ #Account creation date
129+ while True :
130+ while True :
131+ hyear = input ("Enter account_creation year (4 int): " )
132+ if len (hyear ) == 4 :
133+ try :
134+ hyear = int (hyear )
135+ print ("Done OK" )
136+ except ValueError :
137+ print ("year should be an integer!!" )
138+ else :
139+ break
140+ else :
141+ print ("Year consists of 4 integers!!" )
142+
143+ while True :
144+ hmonth = input ("Enter account_creation month (2 int) (01 to 12): " )
145+ if len (hmonth ) == 2 :
146+ try :
147+ hmonth = int (hmonth )
148+ print ("Done OK" )
149+ except ValueError :
150+ print ("month should be an integer!!" )
151+ else :
152+ break
153+ else :
154+ print ("Month consists of 2 integers!!" )
155+
156+ while True :
157+ hday = input ("Enter account_creation day (2 int) (01 to 31): " )
158+ if len (hday ) == 2 :
159+ try :
160+ hday = int (hday )
161+ print ("Done OK" )
162+ except ValueError :
163+ print ("Date should be an integer!!" )
164+ else :
165+ break
166+ else :
167+ print ("Date consists of 2 integers!!" )
168+
169+ try :
170+ acc_creation_date = date (hyear ,hmonth ,hday )
171+ except ValueError :
172+ import traceback
173+ traceback .print_exc ()
174+ else :
175+ if age (birth_date )- age (acc_creation_date )>= 10 :
176+ break
177+ else :
178+ print ("client must atleast be 10 years of age!!" )
179+ #client password/pin
180+ while True :
181+ password = input ("Enter client login password(max 8 characters, min 4): " )
182+ lp = len (password )
183+ if lp > 8 :
184+ print ("Max 8 characters only." )
185+ elif lp < 4 :
186+ print ("Minimum 4 characters to be entered." )
187+ else :
188+ break
189+
190+ #mobile no
191+ while True :
192+ mobile_no_str = input ("Enter mobile no. (7 to 15 int)" )
193+ mobile_no = mobile_no_str
194+ #Thanks to the international phone numbering plan (ITU-T E. 164),
195+ #phone numbers cannot contain more than 15 digits. The shortest
196+ #international phone numbers in use contain seven digits.
197+ try :
198+ mobile_no = int (mobile_no )
199+ except ValueError :
200+ print ("acc_no should be an integer!!" )
201+ else :
202+ if len (mobile_no_str )> 6 and len (mobile_no_str )< 16 :
203+ mobile_no = mobile_no_str
204+ lmn = len (mobile_no )
205+ break
206+ else :
207+ print ("Mobile number can have min 7 digits and max 15!!" )
208+
209+ #email-id
210+ while True :
211+ email_id = input ("Enter client Email ID (max 25 char):" )
212+ if len (email_id )< 26 :
213+ break
214+ else :
215+ print ("Maximum 25 characters" )
216+
217+
218+
219+ print ("=========== Final Data ===========" )
220+ print (acc_no ,acc_type ,first_name ,last_name ,gender ,birth_date ,acc_creation_date ,mobile_no ,email_id ,password )
221+ add_client = ("INSERT INTO clients "
222+ "(acc_no,acc_type,first_name,last_name,gender,birth_date,acc_creation_date,mobile_no,email_id,pass) "
223+ "VALUES (%s,%s,%s,%s,%s,%s,%s,LPAD(%s,%s,'0'),%s,LPAD(%s,%s,'0'))" )
224+ data_client = (acc_no ,acc_type ,first_name ,last_name ,gender ,birth_date ,acc_creation_date ,mobile_no ,lmn ,email_id ,password ,lp )
225+ try :
226+ cur .execute (add_client , data_client )
227+ query .commit ()
228+ except mysql .connector .Error as err :
229+ print (err .msg )
230+ print ("-----------Value addition was unsuccessful!!!!-------------" )
231+ else :
232+ print ("Values added successfully!!" )
233+ cur .close ()
234+ query .close ()
0 commit comments