Posterous
olek is using Posterous to post everything online. Shouldn't you?
A
 

olek’s posterous

random

Python: bot gadu-gadu

Nie ma to jak trochę wolnego czasu. Taki sobie pseudo framework bota Gadu-Gadu w postaci plugina do ekg. Słownik callbacks zawiera funkcje, które obsługuje bot. Ciało tych funkcji musi zawierać sie nad nim by nie było błędów. Jeżeli wartość zwracana przez funkcje ma być wielo linijkowa, użyj lambdy ret aby połączyć liste zawierającą odpowiedź w 1 wiadomość zwrotną.

#!/usr/bin/python
# -*- coding: utf-8 -*-
import ekg, re, urllib2

# zewnetrzne moduly uzyte w funkcjach
import shortener

ekg.config.uin = numerek
ekg.config.password = 'haslo'


ret = lambda result: '\n'.join(result)

def tnij(msg):
    '''Skracanie linkow, po przecinku mozna dawac kilka'''
    result = []

    for longUrl in msg:
        result.append(shortener.shorten(longUrl))


    result.append('Aby sprawdzic ile bylo odwiedzin na danym linku dodaj /hits d
o adresu')
    return ret(result)

def reverse(msg):
    '''Odwraca podany ciag znakow, bezuzyteczne'''

    result = ' '.join(msg)

    return result[::-1]

def get_help(msg):
    '''Wlasnie to ogladasz'''
    result = []

    for k, v in callbacks.iteritems():
        result.append(str(k) + ' : ' + str(v.__doc__).strip())


    return ret(result)

callbacks = {
             'pomoc': get_help,
             'odwroc': reverse,
             'tnij' : tnij,
            }

def init():
    return 1


def deinit():
    return 1

def handle_msg(uin, name, msgclass, text, time, secure):
    msg = re.split('\s', text)
    if not callbacks.has_key(msg[0]):
        ekg.command('msg %d Sorry, nie wiem o co Ci chodzi. Moze wpisz pomoc' %

uin)
        return 2

    result = callbacks[msg[0]](msg[1:])
    ekg.command('msg %d %s' % (uin, result))

    return 2

Filed under  //   gadu-gadu   python  
Posted April 30, 2009
// 1 Comment

Play him off, keyboard cat favorite

Filed under  //   youtube  
Posted April 27, 2009
// 0 Comments

kot'n'roll

  
(download)

pioseneczka z np.

Filed under  //   youtube  
Posted April 27, 2009
// 1 Comment

Menstral : Menstrual Calendar for Mobile Phones

Check out this website I found at menstral.net

control your period :)

Posted April 20, 2009
// 0 Comments

python listing

pajtonowa klasa do przeglądania programu tv, lista odświeżana przy tworzeniu instancji obiektu ;-)


import re, urllib, sys

class TvProgram:
    def __init__(self):
        self.url = '<a href="http://tv.o2.pl/program/" mce_href="http://tv.o2.pl/program/">http://tv.o2.pl/program/</a>'
        self.tv_list = {}
        
        html = urllib.urlopen(self.url).read()
         pat = re.compile('<option value=(\d{1,2}) > (.*)')

        for m in pat.finditer(html):
            self.tv_list[m.group(2).lower().strip()] = m.group(1)
    
    def get_channel(self, channel, day = 0):
         try:
            id_channel = self.tv_list[channel]
        except KeyError:
            raise
        
        query = { 'id_stacja' : id_channel,
                  'dzien' : day }
         
        html = urllib.urlopen(self.url, urllib.urlencode(query)).read()
        pat = re.compile(r'(?P<time>\d{2}:\d{2})(.|\n)+?<b>(?P<title>.*)</b>')
        
        for m in pat.finditer(html):
             yield m.group('time'), m.group('title')
        

def main():
    tv_prog = TvProgram()
    
    try:
        for time, title in tv_prog.get_channel('tvn'):
            print time, title
     except KeyError:
        print 'Nie znaleziono stacji'
    

if __name__ == '__main__':
    main()

Filed under  //   python  
Posted April 19, 2009
// 0 Comments

Hello World

Siemano, ale spoko ?

Posted April 19, 2009
// 0 Comments