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()

10 mars 2010

Je vais à Confoo

Filed under: Non classé — Jean Schurger @ 2:01

confoo.ca Web Techno Conference

Filed under: Code,Gnome,Python — Jean Schurger @ 1:59

Tired of typing your #freenode password when ERC is connecting ? You don't want to write you passwords as clear text in your .emacs files ?

Lets see how to store, passwords in the Gnome Keyring, and access it from Emacs. It only needs Pymacs and gnome-keyring python bindings.

  • Write a little module to read and write passwords. This module will be loaded my pymacs and its functions will be available from emacs-lisp. You may name your module 'gnome-keyring.py' and store it somewhere like '~/.emacs.d/pymacs/'
def get_password(name):
    import gnomekeyring as gk
    try:
        items = gk.find_items_sync(gk.ITEM_GENERIC_SECRET,
                                   dict(variable_name=name))
    except gk.NoMatchError:
        return None
    return items[0].secret
get_password.interaction = ""

def set_password(name, password):
    import gnomekeyring as gk
    gk.item_create_sync(gk.get_default_keyring_sync(),
                        gk.ITEM_GENERIC_SECRET,
                        "Emacs password", dict(variable_name=name),
                        password, True),
set_password.interaction = ""

  • Load the module using pymacs
(require 'pymacs)
(add-to-list '
pymacs-load-path "~/.emacs.d/pymacs/")
(pymacs-load "gnome-keyring" "gnome-keyring-")

  • Trying from the interactive emacs lisp mode (M-x ielm)
ELISP> (gnome-keyring-set-password "my-password" "p4$$w0rD")
nil
ELISP> (gnome-keyring-get-password "my-password")
"p4$$w0rD"

  • And now, an example for ERC
(setq erc-password (gnome-keyring-get-password "my-password"))
(setq erc-prompt-for-password nil)

Too easy ! :D

Powered by WordPress