Changes between Initial Version and Version 1 of SujetTP7-2018


Ignore:
Timestamp:
Apr 9, 2015, 4:03:07 PM (10 years ago)
Author:
franck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SujetTP7-2018

    v1 v1  
     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
     21import BaseHTTPServer
     22import CGIHTTPServer
     23import cgitb; cgitb.enable()
     24
     25server = BaseHTTPServer.HTTPServer
     26handler = CGIHTTPServer.CGIHTTPRequestHandler
     27server_address = ("", 8000)
     28handler.cgi_directories = ["/cgi"]
     29
     30httpd = server(server_address, handler)
     31httpd.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
     53LED:<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
     59Statistiques:<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
     71import cgi
     72form = cgi.FieldStorage()
     73val1 = form.getvalue('val1')
     74
     75print """
     76<html>
     77<body>
     78<p><a href="/peri.html">home</a></p>
     79
     80La valeur est ... %s<br/>
     81</body>
     82</html>
     83""" % (val1,)
     84}}}
     85
     86'''charts.py'''
     87{{{
     88#!/usr/bin/env python
     89import cgi
     90form = cgi.FieldStorage()
     91#val1 = (int)(form.getvalue('val1'))
     92val1 = 20
     93tab = [10,12,20,70,60,40]
     94
     95print """
     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']"""
     105i=0
     106while i <= val1:
     107  print "         ,['%d', %d]" % (i,tab[i/4])
     108  i += 4
     109print """\
     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}}}