May 09, 2008

For those of you who don’t know TarPipe, it is a web application that makes it easier to create your workflows on the web. This workflow above just receives via the API a title and a photo and uploads it to Photobucket (which sucks, but a Flickr Connector, among others, is being released very soon) and the enters the image link in my flickr account. Right now Tarpipe hasn’t launched yet, but I have access to developer’s preview (which you may also ask) and I have played with it’s API.
So I picked my language of choice: Python and I made a library to access TarPipe API from Python. And it’s as easy as:
sudo easy_install tarpipe-python
python
And then
import tarpipe
t = tarpipe.TarPipe(token="your workflow token")
t.upload(title="hello from python",body="testing TarPipe from Python",image="/Users/youruser/Images/test.png")
As simple as that. The project is hosted at Google Code (you can checkout from the svn if you want). And it’s licensed under LGPL, which will deserve a post later on.
May 05, 2008
This shirt explains it all. (Via Paulo Abreu)
May 02, 2008
So Twitter is leaving Rails and I bet Rails programmers are not happy with this. Their #1 success application at a large scale is leaving the building. I guess now it’s more difficult for them to persuade businesses to start using Ruby on Rails.
One the other hand, Jaiku is moving in to Google App Engine and I guess they’re using Python. They’re minimizing the risk of scaling issues (something they could have learned form Twitter’s success). I still wonder what’s the key think that makes them working on Jaiku. Is it Android? Or some killer-feature?
April 13, 2008
I sincerely believe Dynamic Languages are the future. Once people start learning these languages, they’ll hardly go back. I know a lot of guys, like me, to whom programming in C, Java or C# is painful. Most of people won’t learn any of this “new” (they’re so damn old!) languages. If you think right, they make you more productive!
So why Python? Well, I’ve spend many years coding PHP and I don’t want to do that again! (I know I will, and because it will the best choice, but I won’t have the same feeling as in coding Python). As for PERL, it is really good for those who learned it years ago. Nobody learns it nowadays. Ruby and Python are as powerful as Perl, and much more readable. As for Ruby, it is indeed a powerful language. I happen to love some of its features, but the simplicity of Python rocks my world. Ruby is almost used with Rails, which I also like, but it alone can’t make me change my language. Of course there is Shoes also, but that’s just for fun.
In Python I have all another world. I also have webdev with Django (which fits my specific needs better than rails) and I also have scripting and desktop apps. Do you know that a lot of the frontend of the applications you use daily in Linux distros like Ubuntu are mostly written in Python?
But the best is yet to come. I believe Python will be the next big languages. Not for developers (who will use something like Javascript with a bit of Ruby), but for PowerUsers. Society is getting more into computers and kids can now learn advanced stuff faster. In a few years, all software should be scriptable, and regular people will make small python scripts to change the way each program flows. And that’s what will Python be for. So if you do software development, you can see how easy it is to allow such thing in .NET.
I would also recommend reading Gobán Saor’s post on Python the new VBA which details more of this idea.
April 12, 2008
I am a Python addicted :/
alcides$ history | awk '{print $2}' | sort | uniq -c | sort -rn | head
125 cd
100 python
78 ls
33 clear;
23 ssh
16 ipy
15 ping
10 sudo
10 rm
10 easy_install
March 31, 2008
On my talk at TechDays2008, I noticed the audience was looking more to integrate IronPython/IronRuby on their existing C# apps, than using it as a standalone language. In order to get one of this two languages in your application is to host a DLR engine.
It’s very easy to do this, so easy I guess it will be be used, even when it’s not the best solution (just an hintch). As usual, Michael Foord puts it plain simple, with a couple of examples for you to get started.
This is a great excuse to start allowing scripting over you application, using one (or even both!) of this great languages! As I mentioned in my presentation, there are power users who would want to code something in this languages (that are really, really simple!) and start using the full power of your application!
March 24, 2008
Yahoo has lanched Fire Eagle, a way of providing your location to several services. Good news to Python Hackers, Steve Marshall has published his bindings to the Fire Eagle API. Also in the Python world, Simon Willison has done a really cool mashup envolving FireEagle and Wikipedia (along with some Google Stuff) sticking it all inside a Django Project. And he also explains how he made it.
Among the best of the web I found a link to Richard Crowley’s blog. I found there three cool hacks, specially the last two. The first is PownceFS and implementation of your Pownce friends archives as a filesystem. Systems like this and like DropBox, that connect the desktop and the web are stuff that I believe in. Oh, and take a look at TarPipe when it comes out (or earlier at Take Off!).
The other two are some UserScripts to improve you Google Reader experience. I use it as the my major source of information (email being only for private stuff and twitter… you can’t really call it information, can you?) but I archive stuff in my delicious account, so now I have what I’ve been looking for in a while: being able to bookmark posts directly to Delicious inside Google Reader.
The last one, is another script to see that original link for that post but inside GoogleReader, which I find very handy to comment a post, or see some youtube video GReader insists on not parsing.
March 17, 2008
Quinta feira fiz a minha apresentaçãozinha no TechDays. Lá tentei convencer a audiência das vantagens (e algumas desvantagens, claro) das Linguagens Dinâmicas, e da sua utilização em .NET. Ficam por aqui os slides e os demos para o caso de alguém querer dar uma olhadela, mas ficava muito melhor contextualizado.
Para terem uma ideia, falei das razões que me levam a acreditar que as linguagens dinâmicas são o próximo passo (na evolução assembly – C – Java/C#) e em como são linguages muito mais alto nível. contei também um bocadinho da história do DLR e do estado actual das linguagens dinâmicas. Demonstrei a integração com o Visual Studio e a interacção com managed code em C#. Falei também das situações em que usar linguagens dinâmicas pode ser uma vantagem (e mostrei algum código exemplo). Acacabei referenciando exemplos de aplicações de IronPython no mundo real.
Deixo também alguns recursos adicionais para quem estiver interessado em explorar estas novas linguagens em .NET:
IronPython
IronRuby
DynamicSilverlight – Site específico com informações e tutoriais sobre linguagens dinâmicas para Silverlight
Aprender Python em 10 minutos para quem já sabe outra linguagem
Aprender Ruby em 20 minutos
Poignant Guide to Ruby – Um tutorial cheio de humor, para quem tiver mais tempo.
Michael Foord’s Introduction to IronPython - Muito bom para entrar em IronPython. É também o autor do primeiro livro sobre o assunto.
Learning IronPython – Um bom tutorial para aprender IronPython
Blogs:
IronPython
John Lam
Jim Hugunin
March 02, 2008
That’s true, I’m finally learning Django. Since I haven’t had no big website until now, I’ve been using my microwebframework pungi. But for large websites I feel the need for something more powerful and scalable.
I’ve been following (well, almost) the tutorial on the website adapting it to my needs. I’ve now reached the template part and I wondering if Django’s default template system is the best approach. I am pretty familiar with HTML and I even find it natural to write using XML tags, but I’m not sure if this is the best approach.
I’ve been looking for some alternatives (Yeah, Django is great because you can use whatever template language you want without any trouble!) and I found Brevé, a python DSL (or little language) for HTML generation. Writing Python is so much simple than the weird XML syntax. But I’m already used to HTML, so I got a problem here. And I believe there would be a more pythonic way of representing HTML. I feel ruby’s HTML generation in the CGI module (scroll down to “Print http header and html”) more readable than python lists. But okay that’s just my personal opinion.
I also took a look at PyMeld. Not quite a template language, but a way of manipulating HTML, that would have the same effect, but I believe Django’s template system is easier.
I could also use a client-side javascript template system, like MV suggests but I think neither me nor the world is ready for such thing.
So what would you choose if you were me?
February 19, 2008
Ou, mais pomposamente, como o Nuno escreve: Primeiro contacto com programação por parte dos alunos do ensino superior. Ele defende os Haskell pelas suas razões. Cá eu, tenho uma opinião diferente, e quem me conhece destas bandas já o adivinhou: Python.
O meu curso até há uns tempos tem sido mais uma daquelas escolas horríveis de Java, mas com a remodelação para bolonha isso foi corrigido. Das quatro cadeiras de programação que temos, usamos Python, C, Java para as três primeiras e na quarta uma qualquer das anteriores (visto que se baseia apenas em algoritmos). Acho bem começar com Python. É uma linguagem de alto nível, que pela sua simplicidade serve perfeitamente para transmitir os conceitos básicos de ciclos, funções, recursividade, e dá aos alunos a capacidade de já poderem fazer programas e scripts que lhes sejam úteis no dia a dia. Depois é dado C para chegar a um nível mais baixo, que também é essencial saber. Depois na cadeira de POO damos Java, embora eu sugeria fortemente Ruby, mas nem é o que me preocupa mais.
Mas eu acho que está aqui uma coisa mal, a programação não devia ser ensinada no ensino superior, mas sim a nível do ensino secundário (e lá mais para a frente a nível do básico). Quem está na área científica, devia logo aprender a programar, porque o seu curso vai ter sempre uma cadeira de informática (ok, há umas poucas que não dentro da área da saúde) e ter capacidade de escrever um script em Python (ou uma outra) para automatizar o seu trabalho é sempre uma mais valia, e cada vez mais imprescindível. Já para economia, deviam saber trabalhar com bases de dados, mas se calhar também já estou a exagerar.
Estou também a ver se junto um grupo de alunos do 8º ano para lhes ensinar a programar, porque acredito que é essa a idade ideal. Linguagem? Python (ou IronPython). Depois mostro os resultados ;)
February 07, 2008
After I read that OpenStruct was now in Ruby core, I had to do it in Python:
class OpenStruct:
def __init__(self, **dic):
self.__dict__.update(dic)
def __getattr__(self, i):
if i in self.__dict__:
return self.__dict__[i]
else:
raise AttributeError, i
def __setattr__(self,i,v):
if i in self.__dict__:
self.__dict__[i] = v
else:
self.__dict__.update({i:v})
o = OpenStruct(b=2)
o.a=1
print o.a,o.b
Will they take it into the Python core? Nooo, but is cool to code nevertheless, and may be used sometimes :)
February 03, 2008
It’s ironic, when Python tries to get rid of lambda expressions, it’s when Java sees the light (and after C#).
I can’t wait to see what they’ll borrow from dynamic languages next (and I mean having lambda inside OOP code, and not lambda expressions themselves).
January 28, 2008
Hail king of the python parsers! Will you (or anyone who is cool enough) port Mofo (and Hpricot) to Python?
Until now, there was already this one that I couldn’t even put to work. And its old and lacks of many microformats.
I have found this one in beta but it has too many dependencies and sucks to have that all in shared hosting :/
I am really liking Mofo, but not liking ruby that much! But fits in all my current projects (I won’t release its source so you wont make fun of my ugly code!)
December 30, 2007
I love Python! I love .NET! Therefore I love IronPython. It let’s you do WinForms, Speech, WPF with XAML, work with ANY .NET managed library. I am even using it to do games with XNA! And the Visual Studio integration… It gives Python programmers the tools they dream about: A debugger, intellisense and a compiler.
(I will post about my IronPython adventures in the future).
But there is just one thing that I don’t like in it. It just isn’t Python! It is the Python Language, yes, but it’s not the CPython implementation. I am now stuck with two Python Consoles and there is no way of distinguish IronPython code from regular Python. Of course IronPython is way faster, but sometimes installing it and living with two pythons isn’t always the best choice.
That’s why I really enjoyed the Python.Net. It’s a way of extending Python to access the .NET framework existent in you environment. And now they are making it compatible with IronPython code! And you can still work with all the other python modules (Not all are yet implemented in IronPython). There is only one small problem: It’s alpha software and still very unstable.
I downloaded from the trunk and compiled it with VS2005. I made the binaries available for you and should work fine in Windows XP with .NET framework 1.1, 2.0 and even 3.0 with Python 2.5 except for this bug I reported. Check the readme anyway. It’s also possible to compile to use Mono, but if you really want it, you should be able to compile it yourself ;)
December 30, 2007
I’ve read a nice post on PythonLovers by Brett Cannon about wxPython and the lack of a good GUI approach in Python.
Last year I did some wxPython, pyGTK and TkInter, both cross-platform GUIs and none of them satisfied me. My final choice was wxPython thanks to wxGlade, a nice WYSIWYG form editor. However there is a great con to TkInter: wxPython needs a separated installer. But TkInter is so damn ugly!
I believe Python should change their approach on GUIs. I believe each python distribution should include the native wrapper for each target. Gnome Linux Dists would come with PyGTK, KDE ones with PyQT, MacOS with PyObjC (Which I believe it’s already included, or at least comes with Leopard) and Windows with… Python.NET (more on this in the next post). And then a Universal Wrapper that would allow programmers to write one single simple code (Shoes anyone?) that would run in all OSes. Almost a mix between PyGUI and TwilightGUI. And specific development would always be possible using the lower-level bindings.
I know that this has much more dependences on external code than the TkInter solution, but Python is no more a scripting language for hackers/sysadmins like PERL, but a full-featured language that is wanted to be used for all purposes. And along with a standard good package manager (like ruby’s gems), the GUI issue is one of the biggest disadvantages in Python. And Guido seems not to care much about it.
December 24, 2007
Yesterday I was implementing a OOP structure of Poker in Python for a friend, and I wanted it to be perfect. I even wrote some lambda expressions :) But when it comes of checking for pairs of triples, I wanted the code to be as more extensible as possible. It was late and I hadn’t practice my recursion for a while, so a lot of google searches came out with the following useful code:
def comb(x,n):
"""Generate combinations of n items from list x"""
if n==0:
yield []
return
for i in xrange(len(x)-n+1):
for r in comb(x[i+1:], n-1):
yield [x[i]] + r
A recursive generator! Wow…
December 21, 2007
They say xmas is not about gifts, but about spirituality and love and so. Everybody knows this is not true. And being still a boy, I want this xmas the best toy a hacker could get: a wiimote. Yes, the wiimote only. Unfortunately, I wouldn’t give the wii much use anyway.
And this xmas season, I also wanna ask for some personal hacking time. Here are a few of my projects:
- Playing with the wiimote (specially this and some IronPython XNA games!)
- Since SyncMate and MissingSync do not work with my Leopard Macbook and WM6 Tytn, hack a way to use airsync to manually sync them.
- Since my Pukka trial is expiring, I’m planing on doing a clone in Python.
- Revamp PythonLovers website
- Make a small openid’ed last lists app
- Work on my feed sync protocol
- Learn Pluvo
- Use Windows Live Contacts API to export my MSN contacts to a microformated html page, and then opensource the code.
If you are interested in any or even want to help me, drop something in the comments box ;)
December 06, 2007
Tom Morris posted about showing your love or hate about a particular language. He referred to Dan Simard’s project called ihatephp.net where you can add PHP hate messages through twitter. I guess a Java hate would be necessary too.
But not all are about hate. There are people who do believe their language is divine and want to spread the word. I guess I may try to add this to PythonLovers (that is really needing a redesign) and see what comes around.
If you are interested in this task, please let me know ;)
October 31, 2007
With this popular stuff called blogs, new posts are coming up every millisecond and one post gives birth to another and by the end of the day you got a post about another post that comments yet another post that cites someone else in the blogosphere.
To connect this dots there were created linkbacks that is basically a way of telling a post his has a new child. That I know of there are 3 kinds of linkbacks: Trackback, Pingback and Refback.
Pingback and Trackback are both notifications systems where the linking post tells the linked one “Hey, I am you son!” and Pingback is more secure because he does the DNA exam to be sure (he scans the linking post to see if it really has the link) so that prevents spam, a real issue with Trackback.
As for Refback, it is the black sheep of the family since what he does is record the people who visit your posts and then guesses that they came from a post. They have to be really smart to do this, but generally they are worst than track or pingback, but don’t need some implementation of some awkward protocol.
While people who use Wordpress, Blogger, Movable Type and so on don’t need to worry about this since the software already has that installed, some really weird people that code their own weblog system (I’m referring to myself!) have to learn this stuff and if they want to notify people who they link to, they have to code it themselves.
So last night I did it! And now every time I post, I send both trackbacks and pingbacks to every link in the post, just to be sure. In order to accomplish this, I used Matt Croydon’s Trackback Library and Mathieu Fenniaks Pingback library both in Python with some custom modifications by me to be more an automated process.
Now I can find the fathers of my posts, but I don’t know who my children are… I already started recording the referers, but from what I can see it’s kinda messy and I will probably implement pingbacks in a near future.
October 14, 2007
Over the years Microsoft has done this great marketing that makes (almost) everyone to use their tools, mainly because (almost) all computers ship with Windows pre-installed (Assismática is starting to sell computers with Ubuntu in Portugal) and “simple users” do not know any other alternative.
In this context, I support actions that take opensource (or not) alternatives to some places, like schools (PT) that show people that there are some free (and open) alternatives too. Although I think some Microsoft software is better, I believe each user should make their own decision and to do that, they should know all options. About this, Tecnonov is having its second edition this year and it will be a nice event to show people other options.
A few days ago I saw another perspective to solve this problem: Tom Morris thinks that teaching people how to code they will value more OpenSource alternatives and also help them in their own life with structure thinking. Well I had this idea that management student should learn relational databases since that really helps them organizing stuff. I am happy that someone thought something similar, but taking it farther to programming itself. And he mentions Python, Ruby or other dynamic language to be chosen.
I’m not sure how possible this is, but I’m sure some it would help some people. Any thoughts on this one?
September 18, 2007
Apple did had a great vision buying Coverflow from SteelSkies. It is impressive and very user-friendly for managing images. Now imagine this for Flickr Images! Here you go… “Wooow…” you say.
Well I had this idea a while ago and I tried to do it with Javascript. I used my favorite JS library Prototype and as I don’t have much free time, I used Reflex.js for the coverflow effect.
I then wrote a simple Python cgi file to fetch the images from you flickr account and a javascript file to go through them. Nothing special. You might want to check out the final result.
Well, I believe this can be improvable, maybe making it easy to access other photos than yours (if you know the API is pretty simple) and add more than 3 photos (reflex.js limitation) so we can experience full effect (this might be a little more complex). I am also using the thumbnails from flickr because I want them to be fixe-size square, but using Python ou PHP+GD, we could make it work using larger images.
If you feel like working on this, talk to me and feel free to use the source code for any purpose.
August 10, 2007
Microblogging is becoming more and more used by people in this new Social Web. Twitter arrived and made millions of fans. It was such a success they had problems escalating. Taking advantage of that downtimes, Jaiku got many users to switch over to them, giving them more features. IMO, jaiku is my personal aggregator, not a microblogging service. I sticked to twitter, but had its feed in my jaiku webpage. Only if the feed was updated more frequently…
Some time ago Kevin Rose, the kid from Digg, and his team (including my dream girl) came up with this microblogging system with Messages, Files, Links and Events that I find very interesting. Only one disadvantage: It only works from the web or the AIR app that cannot be minimized to tray. Thankfully they are getting a public API avaiable soon. In the meanwhile, some guys managed to hack the API used by the desktop app and made a python module.
Well, using this and Python-Twitter, I made a small script that updates both your Twitter and Pownce status at the same time. And a plus: if you enter a url in the message, it will add it as a link in Pownce ;)
Give it a try and comment with feedback please. If it has some success, I’ll probably do some graphical interface, a jabber/msn bot and in the future add the combined list from both your Twitter and Pownce friends.
August 09, 2007
In the between of my paid projects, I managed to get a time to work on my Pungi ultramicrowebframework. Thanks to Nuno Mariz and his dispatcher I managed to get it working on a MVC way that is so hype right now.
I like to develop my frameworks while doing some project that uses it, so I can evaluate it’s strengths and weaknesses better. So I started on an idea that haven’t left my head until then: How much hype does a word have?
With services like Del.icio.us, Technorati, Flickr and so many others, information is being tagged and available for everyone. Well, BUZZwords just gets the results from that word in all of those services, and applies my special formula (not quite just summing them all :P) and returns the hype value for that word.
I later made the page more pretty and added the bars that can make the information more readable at first sight. However there is still a todo: Make a page for each word with it’s evolution through time and the top results from the services used. Oh, and I’m thinking of adding another services, but for example Digg doesn’t uses tags, but I can still perform a search for a word. Would that be a reliable value to consider?
August 07, 2007
I’ve been reading about Python 3000 either in Guido’s blog and all around the web. There are some features I like to see implemented, but mostly I don’t like the course the language is taking.
Among the features I look forward to use, there are the Metaclasses, Revamped Dictionary methods, Module renaming and UTF-8 as default encoding.
There are a few more that I think it gives cohesion to the language, like function annotations (useful for pydoc), new string formatting and making print a function, but I don’t like them. I’ve loved python for being simple, and easy to write and read. This changes are making Python a more “closed” language with the feeling of “There is only one way to write things” that I kinda like. But I really like Ruby’s “function_name parameter1, parameter2” and making all functions callable like that. I mean, if Python hates braces, why does Python can't loose the parenthesis too?
There are other things that are important for me and could be implemented in 3k version. First, the possibility to change core classes. Being a OOP language, makes sense to be able to add methods to the string class for example, so I can call “string example”.send_to_friend(). Some other functions like len() and str() should also be available as methods ( instead of __len__() and then use the function).
One last thing I really miss in Python is a module management system like gems, that could work like ubuntu’s apt-get and have a GUI. I know there is the egg system, but in my opinion is quite weak compared with those. Oh, and a default DB adapter (to make DB-API v2 a real standard).
July 25, 2007
FAQs have been around since 1647 and everybody recognizes it’s worth. Although today they are reached from search engines, They serve their purpose quite well. When you have a doubt, you google for it and most probably you’ll find the answer since someone asked it already.
Well, today I’ll present you another kind of format that is also useful, the Infrequently Answered Questions (IAQ). After checking Wikipedia, in which is said IAQ are used as jokes, I’ve read a real one: Python IAQ.
It comes very handy when you’re exploring the obscure paths of Python language. This IAQ answers some things that most of the people don’t know about. I suggest you read it and bookmark it, because if you work with Python, it might become handy in the future.
Python IAQ was written by Peter Norvig, Director of Research of Google and was head of the Computational Sciences Division at NASA Research Center. He’s been a researcher in the area of Artificial Intelligence and a code guru in Python, Java, Lisp and he was even one of the creators of JScheme. He is also known for his presentation, a satire about bad presentations (reminds me of one of the same type titled “How to prepare good presentations” I gave in my class last year).
July 24, 2007
I’ve been skipping posting in the last days because I’ve been working on a few projects. One of them is now working online and you can see it at http://pythonlovers.com. It’s an python-related aggregator (handcoded) and there already some writers I have invited. If you care about python, you should subscribe this feed in which you’ll learn something useful for sure.
If you have a blog and you post about python (not necessarily python-only), please mail me ;)
July 13, 2007
After Winamp, SongBird and MusikCube I am now using Windows Media Player. You may be thinking why do I use it when it’s so heavy and microsofty. Well, I use it to Sync with my TyTN and it’s one cent coin sized microSD card. But then again, this sync is not really a sync. WMP checks how much space is left and we can send musics there. They are copied even if they already are in the device. One-way sync sucks!
Next, I like to lie down a little lot in the sofa listening to music and watching morangos com açúcar tv. Well, due to my enormous playlist, most of the time I wanna skip songs (no I dont like to make different playlists) and I don’t like to take my wireless keyboard with me to the sofa.
So I’ve looked for WMP remote control programs for my TyTN, but I haven’t found any freeware and nice to use. These are the times I love to be a developer :) First I tried to control it from Python using this but it would only read things from WMP, not to perform actions.
Next, I thought about creating a webservice and then a PocketPC application to consume it. I did it (and can get you the code if you want), but it wouldn’t run in my IIS. Next try: did a ASP.NET website to control the WMP remotly, worked fine but when running on my IIS didn’t worked again. Damn IIS! I removed it and reinstalled, but no good. Looked for any hack or something, and no results. I tried to run ASMX without IIS but didn’t worked either. Next try: Mod_AspDotNet and this time the application was running, but not affecting WMP.
Finally I managed to have it running. How? I compiled a command-line executable (like remotecontrol.exe next/play/stop/previous) and I created a python web script to call it depending on the link clicked. It runs on my own Python CGI Server and I access it from the PDA using PocketIE. I hoped a WirelessLAN solution would be quicker but it takes almost 30 seconds to perform a page query. My webserver responds quickly, the wireless network is fast and PocketIE works fines with internet pages. Maybe one day I’ll find out more.
July 01, 2007
Finally today I revamped ideias3 homepage. It now has a simple page featuring a simple aggregator of this, sergio and ideias3 blogs. It was written in Python with a experimental version of pungi and using universal feedparser to get the info from the RSS feeds, and chardet to solve encoding problems. This one also uses a sorter I found out here instead of traditional bubblesort with auxiliar lists I used to use.
In a near future I’m thinking of creating a full aggregator to use in a project of mine, I will talk about soon.
Source code follows.
#!/usr/bin/python
from pungi import *
import feedparser
import sorter
page=Page('ideias3.html')
# IDEIAS3
posts = []
authors=["Ideias3","Alcides","Sérgio"]
feeds=["http://blog.ideias3.com/main/rss","http://feeds.feedburner.com/alcides","http://feeds.feedburner.com/sergiosantos"]
for feed in feeds:
d = feedparser.parse(feed)
for entry in d['entries'][:min(8,len(d['entries']))]:
title=str(entry['title'].encode('ascii', 'xmlcharrefreplace'))
link=str(entry['links'][0]['href'])
if 'updated_parsed' in entry.keys():
date=entry['updated_parsed']
else:
date=(0,0,0,0,0,0,0,0)
author=authors[feeds.index(feed)]
posts.append({'title':title,'link':link,'date':date,"author":author})
sorter.sort(posts, 'date')
posts.reverse()
body="<ul>"
for entry in posts[:min(15,len(posts))]:
body+="<li><div class='author'>"+entry['author']+":</div> <a href='"+entry['link']+"' target='_blank'>"+entry['title']+"</a></li>\n"
body+="</ul>"
page.add_tag('body',body )
print start_output()
import chardet
final=""
for line in body.split("\n"):
try:
it = chardet.detect(line)
final+= line.replace("<br />","<br />").decode(it['encoding']).encode('utf-8')
except:
final+= line.replace("<br />","<br />")
page.add_tag('body',final)
print page.output()
June 18, 2007
As you might have noticed, I’ve been revamping my website in the last days.
One of the major problems was to deal with the usual stuff developers hate (including me) that Sérgio likes to call wtf-8: encoding issues.
We have a DreamHost account and the python we run there is ASCII. So all the website output was ISO-8859–1 but the content from the feeds ( using feedparser btw) were utf-8. After a few tries, I finally managed to get it right.
First I tried chardet to detect the encoding and then use encode and decode functions like this:
import chardet
for line in page.output().split("\n"):
try:
it = chardet.detect(line)
print line.decode(it['encoding']).encode('utf-8')
except:
print line
But this turned out not to be a good solution, because reading the feed I had to convert it to a useful encode, and I couldn’t encode into UTF-8 a UTF-8 string. So I looked for a better and easy solution and, guess what, I found it. When reading the UTF-8 feed, I had just to use
title=str(entry['title'].encode('ascii', 'xmlcharrefreplace'))
This will convert any character that can’t be converted to ascii into it’s XML Character Referente code. Problem solved.
One thing I also found and I’m looking forward to add to Pungi is a HTML tidy wrapper for Python. uTidylib or mxTidy. However I couldn’t make any of them work on DreamHosting hosting yet. If you had, feel free to help me :)
February 28, 2007
I've just finished my own tagging system.
It's very very simple and I like it :) The main reason I made it was to test Pungi's relation N-N capabilities.
When I got time, I'll add more links for you to check.