Twisted Python Twitter library with OAuth support
I have just pushed OAuth support in my Twitty Twister branch on GitHub. This library created by dustin allows to access the Twitter API using Twisted for Python: a high performance networking engine. It is to my knowledge the first Twitter library written in Python that supports authentication via OAuth. My version of Twitty Twister is backward compatible, allows to choose between standard or OAuth authentication and even allows to change the user’s avatar via OAuth.
![]()
The library does not currently support tokens exchanges (the login flow). So, to use this library and the associated examples you need to register your application on Twitter and get users access tokens using something like Django Twitter Auth for Django.
The 4 first parameters of the examples commands (files ending with -oauth.py in the example/ directory) are always the application’s key, the application’s secret, the user’s key and the user’s secret. See the OAuth Twitter FAQ for futher information.
Have fun!
Patch to use sfXssSafePlugin with symfony 1.2
HTML Purifier is a awesome PHP filter library designed to secure and add standard compliance to HTML. In websites including user generated content, this library allow to have mutlimedia pages including image, text formating and YouTube videos in a secure and SEO proof way thanks to rich text editors like Tiny MCE or FCK Editor and HTML purifier.

A plugin called sfXssSafePlugin is designed to integrate this library as an escapement strategy in symfony. If you have tried it with symfony 1.2 you can see this message:
HTML Purifier autoloader registrar is not compatible
with non-static object methods due to PHP Bug #44144;
Please do not use HTMLPurifier.autoload.php (or any
file that includes this file); instead, place the code:
spl_autoload_register(array(’HTMLPurifier_Bootstrap’, ‘autoload’))
after your own autoloaders.
There are also some strict standards and constants compatibility problems. I’ve just wrote a patch to get this plugin working with symfony 1.2.
- Install sfXssSafePlugin like described in its README file
- Download my patch in the plugin’s folder
- Go into the plugin’s folder and run patch lib/helper/XssSafeHelper.php < XssSafeHelper.php.patch
- Edit your application configuration file (ie: apps/frontend/config/frontendConfiguration.class.php) and add the following code into the
configure()method:require_once(sfConfig::get('sf_plugins_dir').'/sfXssSafePlugin/lib/vendor/htmlpurifier/HTMLPurifier/Bootstrap.php'); spl_autoload_register(array('HTMLPurifier_Bootstrap', 'autoload'));
It’s done ! I’ve submitted this patch to the plugin’s author. I hope it will be upstream soon
Add reCAPTCHA widgets to Symfony forms
I’ve wrote a new Symfony plugin to add reCAPTCHA widgets and validation to Symfony new forms. reCAPTCHA is a free CAPTCHA service that helps to digitize books, newspapers and old time radio shows.

To install: checkout it from http://selfpublish.googlecode.com/svn/trunk/plugins/sfAnotherReCaptchaPlugin/ and put it in your Symfony plugins directory.
Next, get a reCAPTCHA key and put the following lines in your app.yml:
recaptcha:
public_key: <your public reCAPTCHA key>
private_key: <your private reCAPTCHA key>
Clear the cache with the symfony cc and check that the plugin activated in projectConfiguration.class.php.
You are now able to add reCAPTCHA widgets and validators.
See the plugin’s README file or this register form with reCAPTCHA enabled to learn how to use it.
This plugin is distributed under the MIT license and is based on Arthur Koziel work.
Tweet13 sur Presse-Citron
Ok ça date un peu, comme vous avez pu le constater je n’ai pas eu l’occasion de bloguer beaucoup ces temps ci.
Mon dernier jouet pour Twitter, Tweet13, à fait l’objet d’une revue par Eric Dupin sur son blog Presse-Citron. Merci à lui !
Pour rappel Tweet13 est une petite application web qui permet de chiffrer les messages Twitter à l’aide de ROT13 avant des les envoyer.
En parlant d’applications Twitter, je vous en ai concocter une nouvelle sur le thème de la musique qui devrait être disponible sous peu
Joyeuses fêtes à tous.
I need a webdesigner!
Hello Folk!
As a creative web application and software maker I’ve an always increasing need of graphics elements and templates for my projects.
I’m looking for a partnership with a webdesigner. I do the code, you do the design, we share the success (if any)
If you are interested to work with me contact me via the dedicated page of this blog
Jouons un peu avec Tweet13
Voici Tweet13, le dernier petit gadget Twitter que je viens de programmer.
Comme son nom l’indique, Tweet13 chiffre vos updates Twitter avec ROT13 et ajoute optionellement un lien pour déchiffrer le message.
Quel intérêt de chiffrer un message si tout le monde peut le lire ?
Révéler la fin des films que vous avez vu, donner la réponse à de petits quizz que vous avez créés ou encore parler plus crument que d’habitude sans choquer vos followers sensibles
Tweet13 à été développé avec Django, JQuery et l’API Twitter.
Build your own website thumbnail generator with Django
On many website you can see a awesome link preview effect using a thumbnail of the page. There is some web services such as Websnapr or Thumbalizr providing an API to make your own webpages screenshots but it can be annoying to rely on third party projects: free accounts can only display a small among of screenshots and, cannot customize the size of the image, you cannot render Flash animations or Javascript…
![]()
We will build a website thumbnail generator using CutyCapt, a Webkit based free software designed to make screenshots of web pages, and Django, the powerful Python web framework.
The first step is to download and install CutyCapt. On a Debian-based system (such as Ubuntu) just type the following commands:
sudo apt-get install subversion libqt4-webkit libqt4-dev g++
svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
cd cutycapt/CutyCapt
qmake
make
./CutyCapt --url=http://lapin-blanc.net --out=example.png
Try to open the example.png (i.e: eog example.png), if the install is OK you must see a screenshot of this blog.
I assume your Django installation is working fine. Start a new project if needed (django-admin.py startproject mysite) and create an application called webthumb
with python manage.py startapp in your project.

Edit your urls.py file to add a new pattern to the tuple urlpatterns. It will match screenshots requests and call the thumb view:
(r'^thumb/(?P.*)', 'mysite.webthumb.views.thumb'),
Now create a view called thumb in webthumb/view.py with this code:
import os
import subprocess
import md5
from django.http import HttpResponse
CUTYCAPT = '/home/keyes/cutycapt/CutyCapt/CutyCapt'
THUMBS_DIR = '/home/keyes/Documents/Projets/kakofony/thumbs/'
def thumb(request, url):
hash = md5.new(url).hexdigest()
path = THUMBS_DIR + hash + '.png'
print path
if not os.path.isfile(path):
try:
subprocess.check_call([CUTYCAPT,\
'--url=' + url,\
'--min-width=200',\
'--out=' + path])
except subprocess.CalledProcessError:
return django.http.HttpResponseServerError
img = open(path, 'rb').read()
return django.http.HttpResponse(img, mimetype='image/png')
Adapt the variables CUTYCAPT and THUMBS_DIR with your settings. Of course the directory pointed by THUMBS_DIR must be writeable (chmod 777).
You can now embed website thumbnails in your websites just with this HTML markup <img src="http://localhost/thumb/http://lapin-blanc.net" alt="Lapin Blanc" />.
Enjoy !
The last update of Aptana block Django development server
The last update of Aptana Studio come with a new built-in Jetty-based HTTP server running on port 8000… the same as Django development server. There is no good way to disable the preview server feature of the popular editor, but our favorite web framework can be launched on another port. Just type python manage.py runserver 8080 instead of python manage.py and access to your work on http://localhost:8080.
![]()
Quel développeur suis-je ?
- Os : Ubuntu et Mac OS X
- Éditeurs : Eclipse et vim
- Langages favoris : Python, C
- VCS : Subversion
- Navigateur : Firefox
Alors, quel développeur je suis ?

Programmer hierarchy
Un formulaire de création de compte avec Symfony et sfGuard
sfGuard fait parti des plugins Symfony les plus utiles. Il ajoute à notre framework un système de gestion avancé des utilisateurs, groupes et permissions. Il inclut en standard un back office complet ainsi qu’un formulaire de connexion mais pas pour de la création de compte en front.
![]()
Alors qu’il fût assez fastidieux de le réaliser avec la version 1.0 de Symfony, le nouveau système de création de formulaires introduit dans la version 1.1 nous facilite bien la tache.
Je ne reviendrais pas sur l’installation du plugin qui est très bien détaillée dans sa documentation.
Commençons par générer les formulaires associés à nos tables grâce à Propel : php symfony propel:build-forms. Attaquons-nous maintenant à la classe de notre formulaire d’enregistrement. Créez un fichier nommé sfGuardRegisterForm.class.php dans le répertoire lib/form/ qui contient ce code :
<?php
class sfGuardRegisterForm extends sfGuardUserForm
{
public function configure()
{
parent::configure();
/* Ici on ajoute une validation
pour le mot de passe afin qu'il soit long
d'au moins 6 caractères et d'au plus 128. */
$this->validatorSchema['password'] = new sfValidatorString(
array('min_length' => 6, 'max_length' => 128)
);
}
}
Comme vous pouvez le lire, on se contente de créer une classe qui hérite de sfGuardUserForm fournie avec le plugin et d’y ajouter une validation supplémentaire pour le mot de passe (par défaut il peut être vide). C’est également dans cette méthode configure que se déroulera la validation de vos champs personnalisés sur lesquels nous reviendrons plus bas.
Effacez la cache avec la commande php symfony cc. C’est déjà presque fini !
Créons un répertoire sfGuardAuth dans le répertoire modules de votre application puis deux sous répertoires dans sfGuardAuth nommés actions et templates. Ce pseudo-module nous permettre de surcharger le module sfGuardAuth du plugin afin de lui ajouter une action et une vue qui permettront à vos visiteurs de s’enregistrer sur votre site.
Créez un fichier actions.class.php dans le répertoire actions qui contient :
<?php
/* On doit inclure manuellement
l'action du plugin car l'autoloading ne fonctionne pas dans ce cas. */
require_once(sfConfig::get('sf_plugins_dir').
'/sfGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php');
/* Notre action dérive de celle fournie par le module
afin d'hériter de ses actions propres. */
class sfGuardAuthActions extends BasesfGuardAuthActions
{
public function executeRegister($request) {
/* Passe le formulaire à la vue. */
$this->form = new sfGuardRegisterForm();
/* Si l'action est appelé via la méthode POST... */
if ($request->isMethod('post')) {
$this->form->bind(
$request->getParameter('sf_guard_user')
);
/* ...et que les données sont valides */
if ($this->form->isValid()) {
/* On crée l'utilisateur */
$sf_guard_user = $this->form->save();
$this->getUser()->setFlash('message',
'Vous êtes enregistré,
<a href="/login">connectez-vous</a> !');
$this->redirect('@homepage');
}
/* Sinon le formulaire ainsi que l'erreur sera ré-affiché */
}
}
}
Quand l’utilisateur est créé on redirige le visiteur vers la page d’accueil et on l’avertit grâce à un attribut flash.
Passons à la vue qui se nommera registerSuccess.php et qui se trouvera dans le répertoire templates :
<form action="<?php echo url_for('sfGuardAuth/register') ?>" method="POST">
<table>
<?php echo $form ?>
<tr>
<td colspan="2">
<input type="submit" />
</td>
</tr>
</table>
</form>
Très bien, notre formulaire fonctionne. Mais le plus fort arrive !
Vous avez ajouter des champs personnalisés au profil de votre utilisateur dans la table sf_guard_user_profile (cf. la documentation de sfGuard) ? Régénérez les formulaires associés à vos tables avec la commande php symfony propel:build-forms, effacez la cache à grand coup de php symfony cc, rechargez la page /sfGuardAuth/register et admirez : nos champs sont automatiquement reconnus et affichés. Vous pourrez leur ajouter des étapes de validation dans notre première classe sfGuardRegisterForm ou dans sfGuardUserProfileForm si vous voulez qu’elles s’appliquent à tous les formulaires héritant de cette classe (page de modification du profil, ….).


