· 6 years ago · Dec 13, 2019, 03:18 PM
1
2database.txt
3
4ID: 1
5First Name: 1
6Last Name: 1
7Age: 1
8Email: 1@gmail.com
9Hobby: 1
10--------------------------------------------
11ID: 2
12First Name: 1
13Last Name: 1
14Age: 1
15Email: 1@gmail.com
16Hobby: 1
17--------------------------------------------
18ID: 3
19First Name: 1
20Last Name: 1
21Age: 1
22Email: 1@gmail.com
23Hobby: 1
24--------------------------------------------
25
26
27
28
29---------------------------------------------------------------------
30
31
32class Profile():
33 def __init__(self, id,fname, lname, age, email, hobby):
34 self.id=id
35 self.fname= fname
36 self.lname=lname
37 self.age= age
38 self.email= email
39 self.hobby= hobby
40
41
42
43
44------------------------------------------------------------------------
45
46from FUN import Profile
47from PIL import Image
48import random
49import smtplib
50from email.message import EmailMessage
51import re
52
53
54
55def main():
56 id= 1
57 lis=[]
58 swtich = True
59 print("Welcome to my program !")
60 print("--------------------------------------------")
61 while(swtich):
62 with open('database.txt', 'r') as data:
63
64 print("Enter one of the following options: ")
65 print("1. Add profile")
66 print("2. Display profile")
67 print("3. Display recent profiles")
68 print("4. Search for a profile")
69 print("5. Update profile")
70 print("6. Remove profile")
71 print("7. Remove All")
72 print("8. Pictures")
73 print("9. Resize pictures")
74 print("10. Random number game")
75 print("11. Sending Email for all profiles")
76 print("12. Exit")
77 option= int(input("Your options: "))
78
79
80 if (option == 1): # add into the list
81
82 def enterlis():
83 with open('database.txt', 'a') as database:
84
85 fname = str(input("Enter your first name: "))
86 lname = str(input("Enter your last name: "))
87 age = int(input("Enter your age: "))
88 email = str(input("Enter your email without writing @gmail.com: "))+"@gmail.com"
89 hobby = str(input("Enter your hobby: "))
90
91 database.write('ID: ' + str(id) + "\n")
92 database.write("First Name: "+fname+ "\n")
93 database.write("Last Name: "+lname+"\n")
94 database.write("Age: "+str(age)+"\n")
95 database.write("Email: "+email+"\n")
96 database.write("Hobby: "+hobby+"\n")
97 database.write("--------------------------------------------\n")
98
99 lis.append(Profile(id, fname, lname, age, email, hobby))
100
101 print("")
102
103
104 info = data.read()
105
106 x = re.findall("ID: [0-9]+", info)
107
108 if not x:
109 enterlis()
110
111 else:
112 x = x[-1]
113 x.split("ID: ")
114 x = int(x[4:]) + 1
115 id = x
116 enterlis()
117
118
119
120 elif(option==2): # print the list
121
122 print("")
123 print(data.read())
124 print("")
125
126
127
128 elif (option == 3): # search for an object in the list
129
130 print("")
131 for obj in lis:
132 print("--------------------------------------------")
133 print(f"ID: {obj.id}")
134 print(f"First Name: {obj.fname}")
135 print(f"Last Name: {obj.lname}")
136 print(f"Age: {obj.age}")
137 print(f"Email: {obj.email}")
138 print(f"Hobby: {obj.hobby}")
139 print("--------------------------------------------")
140
141 print("")
142
143 elif(option == 4): # search for an object in the list
144 print("")
145 enter=int(input("Enter the ID you want to display: "))
146 for obj in lis:
147
148 if(enter==obj.id):
149 print("--------------------------------------------")
150 print(f"ID: {obj.id}")
151 print(f"First Name: {obj.fname}")
152 print(f"Last Name: {obj.lname}")
153 print(f"Age: {obj.age}")
154 print(f"Email: {obj.email}")
155 print(f"Hobby: {obj.hobby}")
156 print("--------------------------------------------")
157
158 print("")
159
160 elif(option==6): # remove an object from the list
161 enter= int(input("Enter the ID you want to delete the list: "))
162 for obj in lis:
163 if (enter==obj.id):
164 lis.remove(obj)
165 print("")
166
167 elif(option==7): # clear the list
168 lis.clear()
169 print("")
170
171 elif (option == 8): # image opening
172 print("Enter one of the following Images you want to display: ")
173 print("1. Irelia")
174 print("2. Irelia Mirror")
175 print("3. IG Irelia")
176 print("4. Exit")
177 print("")
178 option2 = int(input("Your option: "))
179 if(option2 == 1):
180 ima = Image.open('Screen Shot 1441-03-13 at 3.10.09 PM copy.png')
181 ima.show()
182 print("")
183
184 elif(option2 == 2):
185 ima2 = Image.open('157338784156073568 copy.png')
186 ima2.show()
187 print("")
188
189 elif(option2 == 3):
190 ima3 = Image.open('Screen Shot 1441-01-28 at 3.03.54 PM copy.png')
191 ima3.show()
192 print("")
193
194 elif(option2 == 4):
195 continue
196 print("")
197
198 else:
199 print("You have entered wrong number please try again")
200 print("")
201
202
203 elif (option == 9): # image resizing with thumbnailing
204 print("Enter one of the following Images you want to display: ")
205 print("1. Resize Irelia")
206 print("2. Resize Irelia Mirror")
207 print("3. Resize IG Irelia")
208 print("4. Exit")
209 print("")
210 option3 = int(input("Your option: "))
211 print("")
212 from FUN import Profile
213 from PIL import Image
214 import random
215 import smtplib
216 from email.message import EmailMessage
217 import re
218
219 def main():
220 id = 1
221 lis = []
222 swtich = True
223 print("Welcome to my program !")
224 print("--------------------------------------------")
225 while (swtich):
226 with open('database.txt', 'r') as data:
227
228 print("Enter one of the following options: ")
229 print("1. Add profile")
230 print("2. Display profile")
231 print("3. Display recent profiles")
232 print("4. Search for a profile")
233 print("5. Update profile")
234 print("6. Remove profile")
235 print("7. Remove All")
236 print("8. Pictures")
237 print("9. Resize pictures")
238 print("10. Random number game")
239 print("11. Sending Email for all profiles")
240 print("12. Exit")
241 option = int(input("Your options: "))
242
243 if (option == 1): # add into the list
244
245 def enterlis():
246 with open('database.txt', 'a') as database:
247 fname = str(input("Enter your first name: "))
248 lname = str(input("Enter your last name: "))
249 age = int(input("Enter your age: "))
250 email = str(
251 input("Enter your email without writing @gmail.com: ")) + "@gmail.com"
252 hobby = str(input("Enter your hobby: "))
253
254 database.write('ID: ' + str(id) + "\n")
255 database.write("First Name: " + fname + "\n")
256 database.write("Last Name: " + lname + "\n")
257 database.write("Age: " + str(age) + "\n")
258 database.write("Email: " + email + "\n")
259 database.write("Hobby: " + hobby + "\n")
260 database.write("--------------------------------------------\n")
261
262 lis.append(Profile(id, fname, lname, age, email, hobby))
263
264 print("")
265
266 info = data.read()
267
268 x = re.findall("ID: [0-9]+", info)
269
270 if not x:
271 enterlis()
272
273 else:
274 x = x[-1]
275 x.split("ID: ")
276 x = int(x[4:]) + 1
277 id = x
278 enterlis()
279
280
281
282 elif (option == 2): # print the list
283
284 print("")
285 print(data.read())
286 print("")
287
288
289
290 elif (option == 3): # search for an object in the list
291
292 print("")
293 for obj in lis:
294 print("--------------------------------------------")
295 print(f"ID: {obj.id}")
296 print(f"First Name: {obj.fname}")
297 print(f"Last Name: {obj.lname}")
298 print(f"Age: {obj.age}")
299 print(f"Email: {obj.email}")
300 print(f"Hobby: {obj.hobby}")
301 print("--------------------------------------------")
302
303 print("")
304
305 elif (option == 4): # search for an object in the list
306 print("")
307 enter = int(input("Enter the ID you want to display: "))
308 for obj in lis:
309
310 if (enter == obj.id):
311 print("--------------------------------------------")
312 print(f"ID: {obj.id}")
313 print(f"First Name: {obj.fname}")
314 print(f"Last Name: {obj.lname}")
315 print(f"Age: {obj.age}")
316 print(f"Email: {obj.email}")
317 print(f"Hobby: {obj.hobby}")
318 print("--------------------------------------------")
319
320 print("")
321
322 elif (option == 6): # remove an object from the list
323 enter = int(input("Enter the ID you want to delete the list: "))
324 for obj in lis:
325 if (enter == obj.id):
326 lis.remove(obj)
327 print("")
328
329 elif (option == 7): # clear the list
330 lis.clear()
331 print("")
332
333 elif (option == 8): # image opening
334 print("Enter one of the following Images you want to display: ")
335 print("1. Irelia")
336 print("2. Irelia Mirror")
337 print("3. IG Irelia")
338 print("4. Exit")
339 print("")
340 option2 = int(input("Your option: "))
341 if (option2 == 1):
342 ima = Image.open('Screen Shot 1441-03-13 at 3.10.09 PM copy.png')
343 ima.show()
344 print("")
345
346 elif (option2 == 2):
347 ima2 = Image.open('157338784156073568 copy.png')
348 ima2.show()
349 print("")
350
351 elif (option2 == 3):
352 ima3 = Image.open('Screen Shot 1441-01-28 at 3.03.54 PM copy.png')
353 ima3.show()
354 print("")
355
356 elif (option2 == 4):
357 continue
358 print("")
359
360 else:
361 print("You have entered wrong number please try again")
362 print("")
363
364
365 elif (option == 9): # image resizing with thumbnailing
366 print("Enter one of the following Images you want to display: ")
367 print("1. Resize Irelia")
368 print("2. Resize Irelia Mirror")
369 print("3. Resize IG Irelia")
370 print("4. Exit")
371 print("")
372 option3 = int(input("Your option: "))
373 print("")
374
375 if (option3 == 1):
376 imag = Image.open('Screen Shot 1441-03-13 at 3.10.09 PM copy.png')
377 he = int(input("Enter height: "))
378 wi = int(input("Enter Width: "))
379 imag.thumbnail((he, wi))
380 imag.save(str(input("Enter the file name you want to save: ")) + ".png")
381 imag.show()
382 print("")
383
384 elif (option3 == 2):
385 imag2 = Image.open('157338784156073568 copy.png')
386 he2 = int(input("Enter height: "))
387 wi2 = int(input("Enter Width: "))
388 imag2.thumbnail((he2, wi2))
389 imag2.save(str(input("Enter the file name you want to save: ")) + ".png")
390 imag2.show()
391 print("")
392 elif (option3 == 3):
393 imag3 = Image.open('Screen Shot 1441-01-28 at 3.03.54 PM copy.png')
394 he3 = int(input("Enter height: "))
395 wi3 = int(input("Enter Width: "))
396 imag3.thumbnail((he3, wi3))
397 imag3.save(str(input("Enter the file name you want to save: ")) + ".png")
398 imag3.show()
399 print("")
400 elif (option3 == 4):
401 continue
402 print("")
403 else:
404 print("You have entered wrong number please try again")
405 print("")
406
407 elif (option == 10): # random game
408 counter = 1
409 switch2 = True
410 print("Welcome to the random number game !")
411 print("Guess the number to win the game !")
412 print("If you want to leave the game press 0\n")
413 print("Enter the following options: ")
414
415 print("1. 1-10")
416 print("2. 1-50")
417 print("3. 1-100")
418 option4 = int(input("Your option: "))
419
420 print("")
421
422 if (option4 == 1):
423
424 while (switch2): # 1 - 10 game
425 random_number = int(random.randint(1, 10))
426
427 enter = int(input(("Enter numbers from 1-10: ")))
428 print("")
429 if (enter == random_number):
430 print(f"WOOO You won it with record {counter} times\n")
431 switch2 = False
432 print("")
433 elif (enter == 0):
434 switch2 = False
435 print("Thank you for playing this game !")
436 print("")
437 else:
438 print("Wrong >.< Try again !\n")
439 print("")
440
441 counter = counter + 1
442 print("")
443
444
445 elif (option4 == 2): # 1 - 50 game
446
447 while (switch2):
448 random_number = int(random.randint(1, 50))
449
450 enter2 = int(input(("Enter numbers from 1-50: ")))
451 print("")
452 if (enter2 == random_number):
453 print(f"WOOO You won it with record {counter} times\n")
454 switch2 = False
455 print("")
456 elif (enter2 == 0):
457 switch2 = False
458 print("Thank you for playing this game !")
459 print("")
460 else:
461 print("Wrong >.< Try again !\n")
462 print("")
463
464 counter = counter + 1
465
466 print("")
467
468 elif (option4 == 3): # 1 - 100 game
469
470 while (switch2):
471 random_number = int(random.randint(1, 100))
472
473 enter3 = int(input(("Enter numbers from 1-50: ")))
474 print("")
475 if (enter3 == random_number):
476 print(f"WOOO You won it with record {counter} times\n")
477 switch2 = False
478 print("")
479 elif (enter3 == 0):
480 switch2 = False
481 print("Thank you for playing this game !")
482 print("")
483 else:
484 print("Wrong >.< Try again !\n")
485 print("")
486
487 counter = counter + 1
488 print("")
489
490
491
492 elif (option == 11): # email
493
494 email = EmailMessage()
495 email['from'] = str(input(("From: ")))
496 email['to'] = ", ".join([i.email for i in lis])
497 email['subject'] = str(input("Subject: "))
498 email.set_content(str(input("Message: ")))
499
500 with smtplib.SMTP(host='smtp.gmail.com', port=587) as smtp:
501 smtp.ehlo() # connection
502 smtp.starttls() # start security
503 smtp.login(str(input("Email: ")), str(input("Password: ")))
504 smtp.send_message(email)
505
506 print("MESSAGE SENT !\n")
507
508 print("")
509
510
511 elif (option == 12): # Exit
512 swtich = False
513 print("")
514
515 else:
516 print("You have entered wrong number please try again\n")
517 print("")
518
519 # main run
520 if __name__ == '__main__':
521 main()
522
523 if (option3 == 1):
524 imag = Image.open('Screen Shot 1441-03-13 at 3.10.09 PM copy.png')
525 he = int(input("Enter height: "))
526 wi = int(input("Enter Width: "))
527 imag.thumbnail((he, wi))
528 imag.save(str(input("Enter the file name you want to save: " )) + ".png")
529 imag.show()
530 print("")
531
532 elif (option3 == 2):
533 imag2 = Image.open('157338784156073568 copy.png')
534 he2 = int(input("Enter height: "))
535 wi2 = int(input("Enter Width: "))
536 imag2.thumbnail((he2, wi2))
537 imag2.save(str(input("Enter the file name you want to save: " )) + ".png")
538 imag2.show()
539 print("")
540 elif (option3 == 3):
541 imag3 = Image.open('Screen Shot 1441-01-28 at 3.03.54 PM copy.png')
542 he3 = int(input("Enter height: "))
543 wi3 = int(input("Enter Width: "))
544 imag3.thumbnail((he3, wi3))
545 imag3.save(str(input("Enter the file name you want to save: " )) + ".png")
546 imag3.show()
547 print("")
548 elif (option3 == 4):
549 continue
550 print("")
551 else:
552 print("You have entered wrong number please try again")
553 print("")
554
555 elif (option == 10): # random game
556 counter= 1
557 switch2=True
558 print("Welcome to the random number game !")
559 print("Guess the number to win the game !")
560 print("If you want to leave the game press 0\n")
561 print("Enter the following options: ")
562
563 print("1. 1-10")
564 print("2. 1-50")
565 print("3. 1-100")
566 option4 = int(input("Your option: "))
567
568 print("")
569
570 if(option4 == 1):
571
572
573 while(switch2): # 1 - 10 game
574 random_number = int(random.randint(1, 10))
575
576 enter=int(input(("Enter numbers from 1-10: ")))
577 print("")
578 if(enter == random_number):
579 print(f"WOOO You won it with record {counter} times\n")
580 switch2= False
581 print("")
582 elif(enter == 0):
583 switch2 = False
584 print("Thank you for playing this game !")
585 print("")
586 else:
587 print("Wrong >.< Try again !\n")
588 print("")
589
590 counter = counter +1
591 print("")
592
593
594 elif (option4 == 2): # 1 - 50 game
595
596 while (switch2):
597 random_number = int(random.randint(1, 50))
598
599 enter2 = int(input(("Enter numbers from 1-50: ")))
600 print("")
601 if (enter2 == random_number):
602 print(f"WOOO You won it with record {counter} times\n")
603 switch2 = False
604 print("")
605 elif (enter2 == 0):
606 switch2 = False
607 print("Thank you for playing this game !")
608 print("")
609 else:
610 print("Wrong >.< Try again !\n")
611 print("")
612
613 counter = counter + 1
614
615 print("")
616
617 elif (option4 == 3): # 1 - 100 game
618
619 while (switch2):
620 random_number = int(random.randint(1, 100))
621
622 enter3 = int(input(("Enter numbers from 1-50: ")))
623 print("")
624 if (enter3 == random_number):
625 print(f"WOOO You won it with record {counter} times\n")
626 switch2 = False
627 print("")
628 elif (enter3 == 0):
629 switch2 = False
630 print("Thank you for playing this game !")
631 print("")
632 else:
633 print("Wrong >.< Try again !\n")
634 print("")
635
636 counter = counter + 1
637 print("")
638
639
640
641 elif (option == 11): # email
642
643 email = EmailMessage()
644 email['from'] = str(input(("From: ")))
645 email['to'] = ", ".join([i.email for i in lis])
646 email['subject']= str(input("Subject: "))
647 email.set_content(str(input("Message: ")))
648
649 with smtplib.SMTP(host= 'smtp.gmail.com', port = 587) as smtp:
650 smtp.ehlo() #connection
651 smtp.starttls()# start security
652 smtp.login(str(input("Email: ")), str(input("Password: ")))
653 smtp.send_message(email)
654
655 print("MESSAGE SENT !\n")
656
657 print("")
658
659
660 elif (option==12): # Exit
661 swtich=False
662 print("")
663
664 else:
665 print("You have entered wrong number please try again\n")
666 print("")
667
668 # main run
669if __name__=='__main__':
670 main()