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
| import sqlite3
conn = sqlite3.connect('my DB.db')
c = conn.cursor()
def insert_list_in_db():
# function used to insert my conctact_list in my DB
for t in contact_list:
#each element of t should be inserted in the rigth coloumn
c.execute('insert into carnet_dadresses values (?,?,?,?,?)',t)
contact_list =[]
class Contact:
nb_contact = 0
def __init__(self , nom, prenom='' , email ='', tel='' , whatsapp = '' ):
self.nom=nom
self.prenom= prenom
self.email=email
self.tel = tel
self.whatsapp= whatsapp
Contact.nb_contact +=1
self.nb=Contact.nb_contact
self=[self.nom,self.prenom,self.email,self.tel,self.whatsapp]
def show(self):
ch = str(self.nb)
print("Contact :" +ch +"\n Nom : "+self.nom +"\n Prenom : "+self.prenom +"\n Email : "+self.email +"\n Tel : "+self.tel +"\n Whatsapp : "+self.whatsapp)
def Add(self):
contact_list.append(self)
def Supprimer(self):
contact_list.remove(self)
def my_contacts(self):
print("List of my contacts :")
for i in contact_list:
Contact.show(i)
def edit_contact(self):
self.nom=input("Entre le nouveau nom :")
self.prenom = input("Entre le nouveau prenom :")
self.email = input("Entre le nouveau mail :")
self.whatsapp = input("Entre le nouveau whatsapp :")
self.tel = input("Entre le nouveau tel :")
def enter_contact(self):
nom = self.nom
prenom = self.prenom
email = self.email
tel = self.tel
whatsapp = self.whatsapp
c.execute("INSERT INTO carnet_dadresses (nom, prenom, email, tel, whatsapp) VALUES (?, ?, ?, ?,?)",
(nom, prenom, email, tel, whatsapp))
conn.commit()
def create_table():
c.execute("CREATE TABLE IF NOT EXISTS carnet_dadresses(nom, prenom, email, tel, whatsapp)")
conn.commit()
C=Contact('eric','jean','sid@h.c','0011','144')
C1=Contact('erric','michel','sid@h.c','1111','1111')
create_table()
insert_list_in_db()
c.close
conn.close() |
Partager