olek's posterous http://olek.posterous.com random posterous.com Thu, 30 Apr 2009 07:42:53 -0700 Python: bot gadu-gadu http://olek.posterous.com/python-bot-gadu-gadu http://olek.posterous.com/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

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/53648/a.ambrozkiewicz_gmail.com_61a93fce.jpg http://posterous.com/people/1lRbLs3uscV olek olek
Mon, 27 Apr 2009 11:43:07 -0700 Play him off, keyboard cat favorite http://olek.posterous.com/play-him-off-keyboard-cat-favorite http://olek.posterous.com/play-him-off-keyboard-cat-favorite

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/53648/a.ambrozkiewicz_gmail.com_61a93fce.jpg http://posterous.com/people/1lRbLs3uscV olek olek
Mon, 27 Apr 2009 10:56:37 -0700 kot'n'roll http://olek.posterous.com/kotnroll http://olek.posterous.com/kotnroll
  
Download now or listen on posterous
kot'n'roll.mp3 (364 KB)

pioseneczka z np.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/53648/a.ambrozkiewicz_gmail.com_61a93fce.jpg http://posterous.com/people/1lRbLs3uscV olek olek -
Mon, 20 Apr 2009 05:56:14 -0700 Menstral : Menstrual Calendar for Mobile Phones http://olek.posterous.com/menstral-menstrual-calendar-for-mobile-phones http://olek.posterous.com/menstral-menstrual-calendar-for-mobile-phones
Check out this website I found at menstral.net

control your period :)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/53648/a.ambrozkiewicz_gmail.com_61a93fce.jpg http://posterous.com/people/1lRbLs3uscV olek olek
Sun, 19 Apr 2009 11:32:00 -0700 python listing http://olek.posterous.com/posterous-re-python-listing http://olek.posterous.com/posterous-re-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 = 'http://tv.o2.pl/program/'         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()

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/53648/a.ambrozkiewicz_gmail.com_61a93fce.jpg http://posterous.com/people/1lRbLs3uscV olek olek
Sun, 19 Apr 2009 05:12:55 -0700 Hello World http://olek.posterous.com/hello-world-704 http://olek.posterous.com/hello-world-704 Siemano, ale spoko ?

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/53648/a.ambrozkiewicz_gmail.com_61a93fce.jpg http://posterous.com/people/1lRbLs3uscV olek olek