| 1 | = Serveur Web minimaliste = |
| 2 | |
| 3 | == Arborescence du site de base == |
| 4 | |
| 5 | {{{ |
| 6 | . |
| 7 | ├── server.py* |
| 8 | └── www |
| 9 | ├── cgi |
| 10 | │ ├── charts.py* |
| 11 | │ └── command.py* |
| 12 | ├── img |
| 13 | │ └── peri.png |
| 14 | ├── index.html |
| 15 | └── peri.html |
| 16 | }}} |
| 17 | |
| 18 | '''server.py''' |
| 19 | {{{ |
| 20 | #!/usr/bin/env python |
| 21 | import BaseHTTPServer |
| 22 | import CGIHTTPServer |
| 23 | import cgitb; cgitb.enable() |
| 24 | |
| 25 | server = BaseHTTPServer.HTTPServer |
| 26 | handler = CGIHTTPServer.CGIHTTPRequestHandler |
| 27 | server_address = ("", 8000) |
| 28 | handler.cgi_directories = ["/cgi"] |
| 29 | |
| 30 | httpd = server(server_address, handler) |
| 31 | httpd.serve_forever() |
| 32 | }}} |
| 33 | |
| 34 | '''index.html''' |
| 35 | {{{ |
| 36 | <html> |
| 37 | <head><title>Peri Web Server</title></head> |
| 38 | <frameset rows="100,*" frameborder=0> |
| 39 | <frame src="img/peri.png"> |
| 40 | <frame src="peri.html" /> |
| 41 | </frameset> |
| 42 | </html> |
| 43 | }}} |
| 44 | |
| 45 | |
| 46 | '''peri.html''' |
| 47 | {{{ |
| 48 | <html> |
| 49 | <head><title>Peri Web Server</title></head> |
| 50 | <body> |
| 51 | <h1>Controle Arduino</h1> |
| 52 | |
| 53 | LED:<br/> |
| 54 | <form method="post" action="cgi/command.py"> |
| 55 | <input name="val1" cols="20"></input> |
| 56 | <input type="submit" value="Entrer"> |
| 57 | </form> |
| 58 | |
| 59 | Statistiques:<br/> |
| 60 | <form method="post" action="cgi/charts.py"> |
| 61 | <input name="val1" cols="20"></input> |
| 62 | <input type="submit" value="Entrer"> |
| 63 | </form> |
| 64 | </body> |
| 65 | </html> |
| 66 | }}} |
| 67 | |
| 68 | '''command.py''' |
| 69 | {{{ |
| 70 | #!/usr/bin/env python |
| 71 | import cgi |
| 72 | form = cgi.FieldStorage() |
| 73 | val1 = form.getvalue('val1') |
| 74 | |
| 75 | print """ |
| 76 | <html> |
| 77 | <body> |
| 78 | <p><a href="/peri.html">home</a></p> |
| 79 | |
| 80 | La valeur est ... %s<br/> |
| 81 | </body> |
| 82 | </html> |
| 83 | """ % (val1,) |
| 84 | }}} |
| 85 | |
| 86 | '''charts.py''' |
| 87 | {{{ |
| 88 | #!/usr/bin/env python |
| 89 | import cgi |
| 90 | form = cgi.FieldStorage() |
| 91 | #val1 = (int)(form.getvalue('val1')) |
| 92 | val1 = 20 |
| 93 | tab = [10,12,20,70,60,40] |
| 94 | |
| 95 | print """ |
| 96 | <html> |
| 97 | <head> |
| 98 | <script type="text/javascript" src="https://www.google.com/jsapi"></script> |
| 99 | <script type="text/javascript"> |
| 100 | google.load("visualization", "1", {packages:["corechart"]}); |
| 101 | google.setOnLoadCallback(drawChart); |
| 102 | function drawChart() { |
| 103 | var data = google.visualization.arrayToDataTable([ |
| 104 | ['heure', 'niveau']""" |
| 105 | i=0 |
| 106 | while i <= val1: |
| 107 | print " ,['%d', %d]" % (i,tab[i/4]) |
| 108 | i += 4 |
| 109 | print """\ |
| 110 | ]); |
| 111 | |
| 112 | var options = { |
| 113 | title: 'lumiere', |
| 114 | hAxis: {title: 'heure', titleTextStyle: {color: '#333'}}, |
| 115 | vAxis: {minValue: 0, maxValue: 100} |
| 116 | }; |
| 117 | |
| 118 | var chart = new google.visualization.AreaChart(document.getElementById('chart_div')); |
| 119 | chart.draw(data, options); |
| 120 | } |
| 121 | </script> |
| 122 | </head> |
| 123 | <body> |
| 124 | <p><a href="/peri.html">home</a></p> |
| 125 | <div id="chart_div" style="width: 600; height: 300px;"></div> |
| 126 | </body> |
| 127 | </html> |
| 128 | """ |
| 129 | }}} |