0% found this document useful (0 votes)
131 views4 pages

Correction Examen Python 19 20

This document contains Python code to analyze SMS data stored in a MySQL database. The code defines functions to read SMS data from the database, filter out spam and advertising SMS, generate a blacklist of numbers, search for a keyword in SMS content, and remove old SMS. The SQL code provided creates a database schema and table to store sample SMS data.

Uploaded by

Khadija Elaouni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views4 pages

Correction Examen Python 19 20

This document contains Python code to analyze SMS data stored in a MySQL database. The code defines functions to read SMS data from the database, filter out spam and advertising SMS, generate a blacklist of numbers, search for a keyword in SMS content, and remove old SMS. The SQL code provided creates a database schema and table to store sample SMS data.

Uploaded by

Khadija Elaouni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Correction Examen Final

Saison normale 2019/2020


Programmation en Python
Master BD2C

verbe.py
class Verbe :
def __init__(self,verbe) :
self.v = verbe.lower().strip()

def _type(self) :
if self.v.endswith("er") and self.v!="aller" :
return "premier"
elif self.v.endswith("ir") :
return "deuxième"
else :
return "troisième"

def type(self) :
print(self._type())

def affiche(self) :
print(self.v)

def conjuguer(self,temps) :
if self._type()=="premier" and temps=="présent" :
p = ["J'" if self.v[0] in 'aeiouy' else "Je ","Tu ","Il ","Nous ","Vous ","Ils "]
t = ["e","es","e","ons","ez","ent"]
for i,j in zip(p,t) :
print(i,self.v[:-2],j,sep="")
# # une autre méthode, n'oubliez pas d'importer le package verbecc
# conjug = verbecc.Conjugator("fr")
# v = conjug.conjugate(self.v)["moods"]["indicatif"][temps]
# for e in v :
# print(e)

v = Verbe("envoyer")
v.conjuguer("présent")

Abdessalam BAKARA
sms.py
from datetime import date,time
from mysql.connector import connect
import re

def LireSms(h,d,u,p) :
sms = {}
try :
mydb = connect(host=h,database=d,user=u,passwd=p)
mycursor = mydb.cursor()
mycursor.execute('SELECT * FROM sms ;')
for l in mycursor.fetchall() :
if l[0] not in sms :
sms[l[0]] = []
sms[l[0]].append([
date(
int(l[1][6:]),
int(l[1][3:5]),
int(l[1][:2])
),
time(
int(l[2][:2]),
int(l[2][3:])
),
l[3]
])
except Exception as e :
print(e)
finally :
return sms

def SupSmsSpam(sms) :
new = {}
for key,value in sms.items() :
for v in value :
if not re.search(r"0808[0-9]{6}",v[2]) :
if key not in new :
new[key] = []
new[key].append(v)
return new

def SupSmsPublicitaires(sms) :
new = {}
for key,value in sms.items() :
for v in value :
if len(re.findall(r"[A-Z]",v[2]))/len(v[2]) < .5 and "$" not in v[2] :
if key not in new :
new[key] = []
new[key].append(v)
return new

Abdessalam BAKARA
def ListeNumerosNoire(sms) :
sans = SupSmsSpam(SupSmsPublicitaires(sms)).keys()
return [num for num in sms if num not in sans]

def ChercherMot(sms,mot) :
num = []
for key,value in sms.items() :
for v in value :
if mot.lower() in v[2].lower().split() :
num.append(key)
return num

def SupSmsVieux(sms,date) :
new = {}
for key,value in sms.items() :
for v in value :
if (date-v[0]).days < 14 :
if key not in new :
new[key] = []
new[key].append(v)
return new

# Juste pour tester


sms = LireSms('localhost','bd2c','root','')
num = ListeNumerosNoire(sms)
print(num)

Abdessalam BAKARA
bd2c.sql
CREATE SCHEMA `bd2c` DEFAULT CHARACTER SET utf8 ;

CREATE TABLE IF `sms` (


`num` VARCHAR(10),
`date` VARCHAR(10),
`hr` VARCHAR(5),
`contenu` VARCHAR(250)
);

INSERT INTO `sms` (`num`, `date`, `hr`, `contenu`) VALUES


('0654342310', '31/10/2018', '10h23', 'Salut, t''es ou ?'),
('0689304059', '30/11/2018', '11h10', 'Adam t''a laissé un message. Rappelle le sur : 08084
32340.'),
('0654394503', '01/12/2018', '09h03', 'T''as pas la solution de l''exo 2 ?'),
('0654394503', '31/12/2018', '09h40', 'Qu''est-ce que tu fias ce soir ?'),
('0660324524', '15/01/2019', '08h30', 'Rdv dans 5 min à la faculté.'),
('0653434325', '16/01/2019', '03h20', 'Le nouveau IPHONE a 5000 $ chez Maroc Telecom.'),
('0522523523', '17/01/2019', '16h23', 'ADIDAS: PLUS QUE 200 MODELES DISPO CHEZ DECATHLON.')
;
COMMIT;

Abdessalam BAKARA

You might also like