From b816959a53c13ceab3d09a1e85a5470dba8320d9 Mon Sep 17 00:00:00 2001 From: Progfou Date: Mon, 10 Jan 2011 01:01:56 +0700 Subject: [PATCH] =?utf8?q?Ajout=20d'un=20script=20WSGI=20pour=20l'annuaire=20?= =?utf8?q?des=20t=C3=A9l=C3=A9phones=20IP=20Thomson=20ST2030.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- partageweb2/partage-compta.py | 5 ++++ voip/ST2030-annuaire.py | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 voip/ST2030-annuaire.py diff --git a/partageweb2/partage-compta.py b/partageweb2/partage-compta.py index 82e86cd..a3d3c89 100755 --- a/partageweb2/partage-compta.py +++ b/partageweb2/partage-compta.py @@ -3,6 +3,11 @@ """ Outil de partage de fichiers. +Copyright : Agence universitaire de la Francophonie — www.auf.org +Licence : GNU General Public Licence, version 2 +Auteur : Jean Christophe André +Date de création : 26 août 2010 + Depends: libapache2-mod-wsgi Attention : le code n'est pas encore “thread-safe”... diff --git a/voip/ST2030-annuaire.py b/voip/ST2030-annuaire.py new file mode 100755 index 0000000..ba2f455 --- /dev/null +++ b/voip/ST2030-annuaire.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Annuaire téléphonique dynamique pour les téléphones IP Thomson ST2030. + +Copyright : Agence universitaire de la Francophonie — www.auf.org +Licence : GNU General Public Licence, version 2 +Auteur : Jean Christophe André +Date de création : 22 octobre 2010 + +Depends: libapache2-mod-wsgi auf-refer + +Attention : le code n'est pas encore “thread-safe”... +""" +import aufrefer + +phonebook_document = u'\n%s\n' +phonebook_entry = u'%(name)s%(phone)s' + +def search(pattern): + phonebook_entries = [] + for user in aufrefer.get('annuaire.json'): + if user['tel_ip'] and pattern in user['adel']: + name = user['adel'].split('@')[0] + phone = user['tel_ip'].replace(' ','') + entry = phonebook_entry % {'name': name, 'phone': phone} + phonebook_entries.append(entry) + return phonebook_document % '\n'.join(phonebook_entries[0:32]) + +def application(environ, start_response): + query = environ.get('QUERY_STRING').lower() + params = dict([x.split('=') for x in query.split('&')]) + if not params.get('mac') or not params.get('search'): + headers = [('Content-Type', 'text/plain; charset=utf-8'), ] + start_response('401 Authorization Required', headers) + return ['Authorization Required'] + data = search(params.get('search')).encode('utf-8') + mime_type = 'text/xml; charset=utf-8' + length = str(len(data)) + headers = [('Content-Type', mime_type), ('Content-Length', length), ] + start_response('200 OK', headers) + return [data] + +if __name__ == '__main__': + # this runs when script is started directly from commandline + try: + # create a simple WSGI server and run the application + from wsgiref import simple_server + print "Running test application - point your browser at http://localhost:8000/ ..." + httpd = simple_server.WSGIServer(('', 8000), simple_server.WSGIRequestHandler) + httpd.set_app(application) + httpd.serve_forever() + except ImportError: + # wsgiref not installed, just output html to stdout + for content in application({}, lambda status, headers: None): + print content + -- 1.7.10.4