diff --git a/Employee_DD.py b/Employee_DD.py new file mode 100644 index 0000000..7944963 --- /dev/null +++ b/Employee_DD.py @@ -0,0 +1,32 @@ +# Creer une classe Employee +# avec une methode __init__ qui prend name et salary comme parametres +# creer une variable de classe globale qui compte les employes, faire des recherches +# creer une methode displaycount qui affichele nombre d'employes +# creer une methode displayEmployee qui affiche un employe + +class Employee(): + nbrEmployes = 0 + + def __init__(self, name, salary): + self.name = name + self.salary = salary + Employee.nbrEmployes += 1 + + def displaycount(self): + print("Total employee = {}".format(Employee.nbrEmployes)) + + def displayEmployee(self): + print("Name : {} salary : {}".format(Employee.name, Employee.salary)) + + +emp01 = Employee("Spamus", 2000) +emp02 = Employee("Eggoz", 5000) +emp03 = Employee("Eggyspa", 7000) + +emp01.displayEmployee() +emp02.displayEmployee() +emp03.displayEmployee() + +emp03.displaycount() + +print("Total employee = {}".format(Employee.nbrEmployes)) diff --git a/Point_DD.py b/Point_DD.py new file mode 100644 index 0000000..cde7225 --- /dev/null +++ b/Point_DD.py @@ -0,0 +1,32 @@ + +''' +Définir une classe Point avec un constructeur fournissant les coordonnées par défaut d’un point du plan +(par exemple : x = 0.0 et y = 0.0). +Définir une classe Segment dont le constructeur possède quatre paramètres : deux pour l’origine et deux pour l’extrémité. +Ce constructeur définit deux attributs : orig et extrem, instances de la classe Point. De cette manière, +vous concevez une classe composite : La classe Segment est composée de deux instances de la classe Point. +Ajouter une méthode d’affichage. +Enfin écrire un auto-test (__str__) qui affiche une instance de Segment initialisée par les valeurs 1, 2, 3 et 4. +''' + + +class Point(): + def __init__(self, x = 0.0, y = 0.0): + self.x = x + self.y = y + + +class Segment(): + def __init__(self, orig1=0, extrem1=0, orig2=0, extrem2=0): + self.orig = Point(orig1, orig2) + self.extrem = Point(extrem1, extrem2) + + def display(self): + return print("Les coordonnees du segment : {}, {}, {}, {} ".format(self.orig.orig1, self.orig2, self.extrem.extrem1, self.extrem.extrem2)) + + def __str__(self): + print("Les coordonnees du segment : {}, {}, {}, {} ".format(self.orig.orig1, self.orig.extrem1, self.extrem.orig2, self.extrem.extrem2)) + + +seg = Segment(1, 2, 3, 4) +seg.display() diff --git a/Rectangle_DD.py b/Rectangle_DD.py new file mode 100644 index 0000000..14a502a --- /dev/null +++ b/Rectangle_DD.py @@ -0,0 +1,39 @@ +# Creer une classe Rectangle +# prenant deux parametres long, larg par defaut = 0 +# une methode surface +# une methode __str__ pour l affichage avec ces caracteristiques long, larg, surface +# +class Rectangle(): + long = 0 + larg = 0 + + def __init__(self, long, larg): + self.long = long + self.larg = larg + + def surface(self): + return (self.long * self.larg) + + def __str__(self): + print("Long = {}".format(self.long)) + print("Larg = {}".format(self.larg)) + print("Surface = {}".format(self.surface())) + + +class Carre(Rectangle): + + def __init__(self): + super.__init__() + self.nom = 'carre' + + +rect01 = Rectangle(4, 3) +rect02 = Rectangle(6, 3) +# rect03 = Rectangle(,) +rect02.__str__() +rect01.surface() + +print('carré') + +carr01 = Carre(2, 2) +carr01.__str__() \ No newline at end of file diff --git a/Web_flask_DD.py b/Web_flask_DD.py new file mode 100644 index 0000000..5066872 --- /dev/null +++ b/Web_flask_DD.py @@ -0,0 +1,40 @@ +from flask import Flask +from flask import request +from flask import redirect, render_template + +app = Flask(__name__) +''' +@app.route('/') +def index(): + return r'
Your browser is : {}
'.format(user_agent) + +@app.route('/user/Test html a tag example
diff --git a/example_bs4_DD.py b/example_bs4_DD.py new file mode 100644 index 0000000..7c581ac --- /dev/null +++ b/example_bs4_DD.py @@ -0,0 +1,61 @@ +from bs4 import BeautifulSoup +import requests + + +helloworld = "Hello World
" +soup_string = BeautifulSoup(helloworld,"html.parser") +print(soup_string) + + +url = "https://www.barnesandnoble.com/b/barnes-noble-classics/_/N-rqv" +response = requests.get(url) +soup_page = BeautifulSoup(response.content,"html.parser") +print(soup_page) + +''' +with open("foo.html") as foo_file: + bs_soup = BeautifulSoup(foo_file, "html.parser") +print(bs_soup) +''' + +html_atag = """Test html a tag example
+Home +Books + +""" + +soup = BeautifulSoup(html_atag, "html.parser") +atag = soup.a +print(atag) + +with open("ecologicalpyramid.html") as jungle: + soup = BeautifulSoup(jungle, "html.parser") + + atag = soup.li.string +print(atag) + + +def is_secondary_consumers(tag): + return tag.has_attr("id") and tag.get("id") == "secondaryconsumers" + + +""" +secondary_consumer = bs_soup.find(is_secondary_consumers()) +print(secondary_consumer.li.div.string) +""" + +''' +# url cible +url = r"https://en.wikipedia.org/wiki/List_of_stations_of_the_Paris_M%C3%A9tro" + +# recuperation du contenu de la cicble +req = requests.get(url) + +# traitement du contenu reçu avec html.parser ici, sinon avec lxml ou html5lib si installés +bs_soup = BeautifulSoup(req.text, "html.parser") + +# affichage de toutes les balises 'th' du contenu +for th in bs_soup.find_all('th'): + print(bs_soup.th) + # print(bs_soup.th.string) +''' \ No newline at end of file diff --git a/example_bs4_OT.py b/example_bs4_OT.py index 3623c0b..ea7ff32 100644 --- a/example_bs4_OT.py +++ b/example_bs4_OT.py @@ -13,8 +13,8 @@ #print(soup_page) #with open("foo.html") as foo_file: -# soup = BeautifulSoup(foo_file, "html.parser") -#print(soup) +# bs_soup = BeautifulSoup(foo_file, "html.parser") +#print(bs_soup) html_atag = """Test html a tag example
diff --git a/example_deco_DD.py b/example_deco_DD.py new file mode 100644 index 0000000..8cdee82 --- /dev/null +++ b/example_deco_DD.py @@ -0,0 +1,86 @@ +import time + + +def deco(func): + def inner(): + print("running inner") + print(func.__name__) + return inner + +# La fonction target devient le parametre de la fonction deco + + +@deco +def target(): + print("running target") + + +target() +print(target) + +registry = [] + + +def register(func): + print("running {}".format(func)) + registry.append(func) + + return func + + +@register +def f1(): + print("running f1") + + +@register +def f2(): + print("running f2") + + +def f3(): + print("running f3") + + +def main(): + print("running main") + print("registry ->", registry) + f1() + f2() + f3() + + +if __name__ == "__main__": + main() + +####################################### + + +def clock(func): + def clocked(*args): + t0 = time.perf_counter() + result = func(*args) + elapsed = time.perf_counter() - t0 + name = func.__name__ + arg_str = ', '.join(repr(arg) for arg in args) + print('[%0.8fs] %s(%s) -> %r' % (elapsed, name, arg_str, result)) + return result + return clocked + + +@clock +def snooze(seconds): + time.sleep(seconds) + + +@clock +def factorial(n): + return 1 if n < 2 else n*factorial(n-1) + + +if __name__ == "__main__": + main() + print('*' * 40, 'Calling snooze(.123)') + snooze(.123) + print('*' * 40, 'Calling factorial(6)') + print('6! =', factorial(6)) diff --git a/station-metro_DD.py b/station-metro_DD.py new file mode 100644 index 0000000..e88c424 --- /dev/null +++ b/station-metro_DD.py @@ -0,0 +1,39 @@ +""" +url = r"https://en.wikipedia.org/wiki/List_of_stations_of_the_Paris_M%C3%A9tro" +Dans ce site web travailler avec les tags th et tr pour retourner tous les noms +des stations de metros et son numero de ligne associe. +choisir son format de donnees +""" + +from bs4 import BeautifulSoup +import requests + + +# url cible +url = r"https://en.wikipedia.org/wiki/List_of_stations_of_the_Paris_M%C3%A9tro" + +# recuperation du contenu de la cible +rqt = requests.get(url) + +# traitement du contenu reçu avec html.parser ici, sinon avec lxml ou html5lib si installé +bs_soup = BeautifulSoup(rqt.text, "html.parser") + +# affichage de toutes les balises 'th' du contenu +metros = bs_soup.td.discendants + +for metro in bs_soup.find_all(["tr", "td", "a"], recursive=True): + if metro.name == 'a': + print(metro.string) + + +############ +''' +for th in bs_soup.find_all("th", recursive=True): + print(bs_soup.th, '\n\n') + print(bs_soup.th.string, '\n\n') + +# affichage de toutes les balises 'tr' du contenu +for tr in bs_soup.find_all('tr'): + print(bs_soup.tr, '\n\n') + print(bs_soup.tr.string, '\n\n') +''' \ No newline at end of file diff --git a/templates/index__DD.html b/templates/index__DD.html new file mode 100644 index 0000000..6eb38a8 --- /dev/null +++ b/templates/index__DD.html @@ -0,0 +1,11 @@ + + + + +azerty
+ + \ No newline at end of file diff --git a/templates/tpl_DD.html b/templates/tpl_DD.html new file mode 100644 index 0000000..16689e6 --- /dev/null +++ b/templates/tpl_DD.html @@ -0,0 +1,10 @@ + + + + +Err0r 404
+ + \ No newline at end of file