From a6768c6c4f1104cb58bbde2714a0e33b36d6036e Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 28 Mar 2018 16:10:17 +0200 Subject: [PATCH 1/6] Mise en place d'un serveur localhost:5000 --- metropolitain_LMO.py | 14 ++++++++------ web_flask_LMO.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 web_flask_LMO.py diff --git a/metropolitain_LMO.py b/metropolitain_LMO.py index e3d58c6..dbe05a8 100644 --- a/metropolitain_LMO.py +++ b/metropolitain_LMO.py @@ -4,7 +4,8 @@ from bs4 import BeautifulSoup import requests -data= [] +stationslist= [] +lineslistlist= [] url = r"https://en.wikipedia.org/wiki/List_of_stations_of_the_Paris_M%C3%A9tro" response = requests.get(url) soup_page = BeautifulSoup(response.content,"html.parser") @@ -12,16 +13,17 @@ for soup_line in soup_table.findAll('tr'): indice = 0 station= "" - linelist= [] + lineslist= [] for soup_case in soup_line.findAll('td'): for soup_station in soup_case.findAll('a'): if(indice == 0): station = soup_station.string if(indice ==3): - linelist.append(soup_station.string) + lineslist.append(soup_station.string) indice += 1 if not station == "": - tmp = [station, linelist] - data.append(tmp) + stationslist.append(station) + lineslistlist.append(lineslist) +dic=dict(zip(stationslist, lineslistlist)) -print(data) +print(dic) diff --git a/web_flask_LMO.py b/web_flask_LMO.py new file mode 100644 index 0000000..5e1d191 --- /dev/null +++ b/web_flask_LMO.py @@ -0,0 +1,10 @@ +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +def index(): + return '

Hello world !

' + +if __name__== '__main__': + app.run(debug=True) From aa62ac066fa9a88149b7402e8f1531a357f67287 Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 29 Mar 2018 15:34:58 +0200 Subject: [PATCH 2/6] =?UTF-8?q?Autorisation=20acc=C3=A8s=20site=20web=20de?= =?UTF-8?q?puis=20une=20autre=20machine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_flask_LMO.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_flask_LMO.py b/web_flask_LMO.py index 5e1d191..f30044b 100644 --- a/web_flask_LMO.py +++ b/web_flask_LMO.py @@ -7,4 +7,4 @@ def index(): return '

Hello world !

' if __name__== '__main__': - app.run(debug=True) + app.run(host='0.0.0.0', debug=True) From 8b8a128cfa5b4e3f358491205ef75503af71978b Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 30 Mar 2018 11:05:51 +0200 Subject: [PATCH 3/6] =?UTF-8?q?D=C3=A9corations=20de=20fonctions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example_deco_LMO.py | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 example_deco_LMO.py diff --git a/example_deco_LMO.py b/example_deco_LMO.py new file mode 100644 index 0000000..5dd0f44 --- /dev/null +++ b/example_deco_LMO.py @@ -0,0 +1,87 @@ + +def deco(func): + def inner(*args): + print("running inner") + return func(*args) + return inner + + +@deco +def target(): + print("running target") + +target() +print("pointeur de fonction target() :", target) +print("L'appel de target est remplacé par inner()") + + +registry = [] + +def register(func): + print("running register {}".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() + + + +import time + + + +def clock(func): + print("toto") + 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)) \ No newline at end of file From ab2f464a4a5cae04fd0cc0a354dc9d1babd05d6b Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 30 Mar 2018 11:23:09 +0200 Subject: [PATCH 4/6] =?UTF-8?q?D=C3=A9corations=20de=20fonctions=20pour=20?= =?UTF-8?q?r=C3=A9cup=C3=A9rer=20les=20requ=C3=A8tes=20du=20site=20web?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_flask_LMO.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web_flask_LMO.py b/web_flask_LMO.py index f30044b..a418ff1 100644 --- a/web_flask_LMO.py +++ b/web_flask_LMO.py @@ -1,10 +1,17 @@ from flask import Flask +from flask import request app = Flask(__name__) @app.route('/') def index(): - return '

Hello world !

' + user_agent = request.headers.get('User-Agent') + return '

Your browser is {}

'.format(user_agent) + #return '

Hello world !

' + +@app.route('/user/') +def user(name): + return '

Hello {} !

'.format(name) if __name__== '__main__': app.run(host='0.0.0.0', debug=True) From 30985f6b06289b8ed33ec3b43a116d5545ef53b7 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 30 Mar 2018 11:42:58 +0200 Subject: [PATCH 5/6] Ouverture page web --- templates/index.html | 1 + templates/t.html | 0 web_flask_LMO.py | 9 +++++++++ 3 files changed, 10 insertions(+) create mode 100644 templates/index.html create mode 100644 templates/t.html diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..01bdf30 --- /dev/null +++ b/templates/index.html @@ -0,0 +1 @@ +

test {{ name }}

\ No newline at end of file diff --git a/templates/t.html b/templates/t.html new file mode 100644 index 0000000..e69de29 diff --git a/web_flask_LMO.py b/web_flask_LMO.py index a418ff1..0cadff3 100644 --- a/web_flask_LMO.py +++ b/web_flask_LMO.py @@ -1,5 +1,6 @@ from flask import Flask from flask import request +from flask import redirect, render_template app = Flask(__name__) @@ -13,5 +14,13 @@ def index(): def user(name): return '

Hello {} !

'.format(name) +@app.route('/test/') +def test(name): + return render_template('index.html', name = name) + +@app.route('/site') +def redir(): + return redirect('https://www.python.org/') + if __name__== '__main__': app.run(host='0.0.0.0', debug=True) From 1b41da86b1d5537c6256cd824e3aae712575630b Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 30 Mar 2018 16:55:19 +0200 Subject: [PATCH 6/6] Ouverture page web --- templates/404.html | 8 ++++++++ templates/index.html | 2 +- web_flask_LMO.py | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 templates/404.html diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..41103b7 --- /dev/null +++ b/templates/404.html @@ -0,0 +1,8 @@ + + + + + Page no found + +{{error_message }} + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 01bdf30..da18dcd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1 +1 @@ -

test {{ name }}

\ No newline at end of file +

test {{ mydict['key'] }}

\ No newline at end of file diff --git a/web_flask_LMO.py b/web_flask_LMO.py index 0cadff3..37ebdb6 100644 --- a/web_flask_LMO.py +++ b/web_flask_LMO.py @@ -18,6 +18,10 @@ def user(name): def test(name): return render_template('index.html', name = name) +@app.errorhandler(404) +def page_not_found(e): + return render_template('404.html', error_message = e),404 + @app.route('/site') def redir(): return redirect('https://www.python.org/')