# -*- coding: utf-8 -*-
import sqlite3
import cgi
print "Content-Type: application/xhtml+xml; charset=utf-8\n"
print '<!DOCTYPE html>'
print '<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">'
print '<head>'
print ' <title>eCarnet - Employées d un service</title>'
print '</head>'
print '<body>'
form = cgi.FieldStorage()
service_id = str(form["service"].value)
db_connection = sqlite3.connect('database.test-01.db')
db_connection.row_factory = sqlite3.Row
cursor = db_connection.cursor()
cursor.execute("SELECT emplacement FROM service WHERE id=" + service_id)
row = cursor.fetchone()
service_nom = str(row['emplacement'])
print ' <h1>Employés du service - ' + service_nom + ' -</h1>'
cursor.execute("SELECT prenom, nom, tel_fixe FROM employe WHERE id_service=" + service_id)
rows = cursor.fetchall()
print ' <ol>'
for row in rows:
print ' <li>' + row['prenom'] + ', ' +row['nom'] + ', ' + row['tel_fixe'] + '</li>'
print ' </ol>'
print '</body>'
print '</html>'
db_connection.close()
Sunday, May 15, 2016
Python CGI Database (2 of 4)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3
print "Content-Type: application/xhtml+xml; charset=utf-8\n"
print '<!DOCTYPE html>'
print '<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">'
print '<head>'
print ' <title>eCarnet - Home</title>'
print '</head>'
print '<body>'
print ' <h1>Bienvenue sur eCarnet de ULB</h1>'
print ' <h2>Employés</h2>'
# Connection à la base de données
#db_connection = sqlite3.connect('database.sqlite3')
db_connection = sqlite3.connect('database.test-01.db')
db_connection.row_factory = sqlite3.Row
cursor = db_connection.cursor()
# Sélection des enregistrements
cursor.execute("SELECT prenom, nom, tel_fixe FROM employe")
# Création de la liste des employées
rows = cursor.fetchall()
print ' <ol>'
for row in rows:
print' <li>' +row['prenom'] + ' ' +row['nom'] + ', ' +row['tel_fixe'] + ' </li>'
print ' </ol>'
# Formulaire de recherche des employés d'un service
print ' <h2>Employés par service</h2>'
print ' <form action="eCarnet_service.py" method="get">'
print ' <p><select name="service">'
cursor.execute ("SELECT id, nom, emplacement From service")
rows = cursor.fetchall()
for row in rows:
print ' <option value="' + str(row['id']) + '">' + row['emplacement'] + '</option>'
print ' </select>'
print ' <input type="submit" value="Lister" /></p>'
print ' </form>'
# Formulaire d'ajout d'un nouvel employé
print ' <h2>Ajouter un nouvel employé</h2>'
print ' <form action="eCarnet_add_employee.py" method="get">'
print ' <p>Prénom : <input type="text" name="prenom" /></p>'
print ' <p>Nom : <input type="text" name="nom" /></p>'
print ' <p>Matricule : <input type="text" name="matricule" /></p>'
print ' <p>Tèl. fixe : <input type="text" name="tel_fixe" /></p>'
print ' <p>Service : <select name="service">'
for row in rows:
print ' <option value="' + str(row['id']) + '">' + row['emplacement'] + '</option>'
print ' </select>'
print ' <input type="submit" value="Ajouter" /></p>'
print ' </form>'
print '</body>'
print '</html>'
db_connection.close()
# -*- coding: utf-8 -*-
import sqlite3
print "Content-Type: application/xhtml+xml; charset=utf-8\n"
print '<!DOCTYPE html>'
print '<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">'
print '<head>'
print ' <title>eCarnet - Home</title>'
print '</head>'
print '<body>'
print ' <h1>Bienvenue sur eCarnet de ULB</h1>'
print ' <h2>Employés</h2>'
# Connection à la base de données
#db_connection = sqlite3.connect('database.sqlite3')
db_connection = sqlite3.connect('database.test-01.db')
db_connection.row_factory = sqlite3.Row
cursor = db_connection.cursor()
# Sélection des enregistrements
cursor.execute("SELECT prenom, nom, tel_fixe FROM employe")
# Création de la liste des employées
rows = cursor.fetchall()
print ' <ol>'
for row in rows:
print' <li>' +row['prenom'] + ' ' +row['nom'] + ', ' +row['tel_fixe'] + ' </li>'
print ' </ol>'
# Formulaire de recherche des employés d'un service
print ' <h2>Employés par service</h2>'
print ' <form action="eCarnet_service.py" method="get">'
print ' <p><select name="service">'
cursor.execute ("SELECT id, nom, emplacement From service")
rows = cursor.fetchall()
for row in rows:
print ' <option value="' + str(row['id']) + '">' + row['emplacement'] + '</option>'
print ' </select>'
print ' <input type="submit" value="Lister" /></p>'
print ' </form>'
# Formulaire d'ajout d'un nouvel employé
print ' <h2>Ajouter un nouvel employé</h2>'
print ' <form action="eCarnet_add_employee.py" method="get">'
print ' <p>Prénom : <input type="text" name="prenom" /></p>'
print ' <p>Nom : <input type="text" name="nom" /></p>'
print ' <p>Matricule : <input type="text" name="matricule" /></p>'
print ' <p>Tèl. fixe : <input type="text" name="tel_fixe" /></p>'
print ' <p>Service : <select name="service">'
for row in rows:
print ' <option value="' + str(row['id']) + '">' + row['emplacement'] + '</option>'
print ' </select>'
print ' <input type="submit" value="Ajouter" /></p>'
print ' </form>'
print '</body>'
print '</html>'
db_connection.close()
Python CGI Database (1 of 4)
<?xml version=“1.0” encoding=“utf-8”?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<meta charset="UTF-8">
<!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />-->
<title>Université libre de Bruxelles</title>
</head>
<body>
<img src="logo_ulb.png" alt="Logo de l'ULB" width="656" height="80" />
<h1>Bienvenue sur le site de l'ULB</h1>
<section>
<h2>Que voulez-vous consulter ?</h2>
<ul>
<li><a href="status.html">Les statuts de l'université</a></li>
<li><a href="/cgi-bin/eCarnet_home.py">Le carnet d'adresses des employés</a></li>
<li><a href="ca.html">La composition du Conseil d'Aministration</a></li>
</ul>
</section>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<meta charset="UTF-8">
<!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />-->
<title>Université libre de Bruxelles</title>
</head>
<body>
<img src="logo_ulb.png" alt="Logo de l'ULB" width="656" height="80" />
<h1>Bienvenue sur le site de l'ULB</h1>
<section>
<h2>Que voulez-vous consulter ?</h2>
<ul>
<li><a href="status.html">Les statuts de l'université</a></li>
<li><a href="/cgi-bin/eCarnet_home.py">Le carnet d'adresses des employés</a></li>
<li><a href="ca.html">La composition du Conseil d'Aministration</a></li>
</ul>
</section>
</body>
</html>
Python CGI Web Server
#! Path to Python.exe "C:\Web development\Python27\python.exe"
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
httpd = HTTPServer(('', 8080), CGIHTTPRequestHandler)
print("Demarrage du serveur web...")
httpd.serve_forever()
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
httpd = HTTPServer(('', 8080), CGIHTTPRequestHandler)
print("Demarrage du serveur web...")
httpd.serve_forever()
Thursday, May 12, 2016
Python and AJAX tutorial for beginners with web.py and jQuery
Kooneiform
Request methods
... a zipped copy of the files in this tutorial, you can get it here. Run app.py and then point your browser to http://localhost:8080 (on Windows; use the appropriate address for your setup).
Request methods
... a zipped copy of the files in this tutorial, you can get it here. Run app.py and then point your browser to http://localhost:8080 (on Windows; use the appropriate address for your setup).
Wednesday, May 4, 2016
Automate the Boring Stuff with Python
Table of Contents
Part 1 - The Basics of Python Programming
- Introduction
- Python Basics
- Flow Control
- Functions
- Lists
- Dictionaries and Structuring Data
- Manipulating Strings
- Pattern Matching with Regular Expressions
- Reading and Writing Files
- Organizing Files
- Debugging
- Web Scraping
- Working with Excel Spreadsheets
- Working with PDF and Word Documents
- Working with CSV Files and JSON Data
- Time, Scheduling Tasks, and Launching Programs
- Sending Email and Text Messages
- Manipulating Images
- Controlling the Keyboard and Mouse with GUI Automation
Invent Your Own Computer Games with Python,
Making Games with Python & Pygame, and
Hacking Secret Ciphers with Python.
His books are freely available under a Creative Commons license from http://inventwithpython.com.
Subscribe to:
Posts (Atom)