Schurger.org

23 mars 2010

Bye bye MSN !

Filed under: Code,MSN,Python — Jean Schurger @ 19:03

Ça y est, je me débarasse de MSN. Mais comme je suis conscient que certaines personnes ne connaissent que ça, voici un petit compromis, qui plus est: éducatif.
Il sagit d'un répondeur automatique à MSN écrit en python, utilisant papyon.

(This is an auto responder for MSN, written in the python language, and using the papyon library)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import signal
import papyon
import papyon.event
import gobject
import logging

logging.basicConfig(level=logging.ERROR)

USER = "user@hotmail.com"
PASSWORD = "p4ssW0rD"
LAYUS = u"""

English bellow.

Bonjour,

  Ceci est une réponse automatique vous expliquant que je ne veux
  plus discuter par MSN.

  En résumé, MSN est fermé, et fonctionne mal.
  Il y a beaucoup d'alternatives libres et efficaces.

  Pour la version longue, lire:
  - http://schurger.org/la-vie-est-possible-sans-msn.html

  Je serai ravi de discuter:
  - En le protocol XMPP (Jabber, Google talk,...).
    (Mon identifiant est jean@schurger.org)
  - Sur IRC, via le serveur irc.freenode.net, mon nickname est jeansch
  - En utilisant la fonction clavardage de Facebook

  Amicalement,

  Jean.

---
 
Hello,

  This is an automatic answer telling why i don't want to chat using MSN.

  Basicaly, the reasons are that MSN is closed and works badly.
  There is a lot of realy great open alternatives.

  For more details, read:
  - http://schurger.org/life-is-possible-without-msn.html

  I'll be happy to chat using:
  - The XMPP protocol (Jabber, Google talk,...)
    (My id is jean@schurger.org)
  - On IRC, on server irc.freenode.net, my nickname is jeansch
  - Using the chat Facebook feature

  Friendly,

  Jean.
"""

class ClientEvents(papyon.event.BaseEventInterface):
   
    def on_client_state_changed(self, state):
        if state == papyon.event.ClientState.CLOSED:
            self._client.quit()
        elif state == papyon.event.ClientState.OPEN:
            self._client.profile.display_name = "Jean Schurger"
            self._client.profile.presence = papyon.Presence.ONLINE
            self._client.profile.personal_message = "Boycott de MSN"

    def on_invite_conversation(self, conversation):
        conversation.send_typing_notification()
        conversation.send_text_message(papyon.ConversationMessage(LAYUS))
        conversation.leave()
       
class Client(papyon.Client):
    def __init__(self, account, quit, http_mode=False):
        server = ('messenger.hotmail.com', 1863)
        self.quit = quit
        self.account = (USER, PASSWORD)
        papyon.Client.__init__(self, server)
        self._event_handler = ClientEvents(self)
        gobject.idle_add(self._connect)

    def _connect(self):
        self.login(*self.account)
        return False

def main():
    mainloop = gobject.MainLoop(is_running=True)
   
    def quit():
        mainloop.quit()
       
    def sigterm_cb():
        gobject.idle_add(quit)

    signal.signal(signal.SIGTERM, sigterm_cb)
    c = Client((USER, PASSWORD), quit)

    while mainloop.is_running():
        try:
            mainloop.run()
        except KeyboardInterrupt:
            quit()

if __name__ == '__main__':
    main()

Powered by WordPress