[Tutor] Loops
pa yo
payo2000 at gmail.com
Fri Feb 13 23:31:35 CET 2009
I need some help.
I have written a filter called Peqibot that takes posts from Twitter
and makes them into wikipages on peqipedia.com
So if you post the following message on Twitter:
>@peqi Tallinn=The capital city of [[Estonia]].
It makes a page on peqipedia.com with "Tallinn" as the headline and
with the article text being "The captial city of [[Estonia]]."
... it seems to be working ok - but I discovered that if someone posts
a message starting with "@peqi" but without an "=" sign the program
crashes.
The way I have come up with to solve this problem is to put the
following loop in:
>> rawfeed = feedparser(http//twitter.com/foobar....)
>> feedstring = rawfeed.split('=',1) #this splits the feed at the first "="
>> headline = feedstring[0] #this is the text infront of the "=" sign.
>> if len(headlinestring) == len(rawfeed) #ie. if the split hasn't worked they will be exactly the same length
>> body = "\x7b\x7bEmpty\x7d\x7d" #this adds an "{{Empty}}" template to the wiki
>> else:
>> body = feedstring[1]
>> #....here I use urllib to encode a post from headline and body that can be posted to the wiki.
But I can't get it to work - I have tried various indents and break
and continues - but I don't know enough about loops to identify what I
have done wrong.
Any advice or suggestions would be great. (it's my first program so
there might well be a better way to avoid this problem in the first
place).
Best wishes
Payo
More information about the Tutor
mailing list