This is a test: Python program in Posterous with Markdown

Posted on

I am using Posterous as the blogging software andsometimes I include computer code in the blog post. Posterous doesn’t likethat. I have included code in the ‘’ tag, but Posterous formats thatin an ackward way. My previous post on Twitter retweet analysis wasformatted wrongly. Posterous claimsto support the Markdown language,so I tried to edit and insert the markdown tag in the raw HTML, but thenit went completely wrong: My code and results were erased!

Now I will try to include the erased code in this blog, submitted by emailand formatted with markdown. According to some markdown documentationcode needs to be indented at least four characters, so that is what I willdo:

from __future__ import division import pymongo from re import compile, search, IGNORECASE, UNICODE connection = pymongo.Connection() db = connection.twitter tweets = db.tweets pattern_url = compile(r"http://", IGNORECASE) stringpatterns_retweet = [ r"^RT @", r"^RTb", r"bRTb" ] patterns_retweet = [ compile(s, UNICODE) for s in stringpatterns_retweet ] total = 0 withurls = 0 retweets = [ 0 ] * len(stringpatterns_retweet) retweets_withurls = [ 0 ] * len(stringpatterns_retweet) for tweet in tweets.find({"delete": {"$exists": False}}):     total += 1     if search(pattern_url, tweet.get('text', '')):         withurls += 1         urlpresent = True     else:         urlpresent = False     for n in range(len(patterns_retweet)):         if search(patterns_retweet[n], tweet.get('text', '')):             retweets[n] += 1             if urlpresent:                 retweets_withurls[n] += 1     if not total % 10000:         print(""" Total         %23d    100.0%% With URLs     %23d    %5.1f%%""" % (total, withurls, 100*withurls/total))         for n in range(len(patterns_retweet)):             print("""Retweet %20s  %7d    %5.1f%% of total Retweet with URLs %10s  %7d    %5.1f%% of total                                          %5.1f%% of retweets                                          %5.1f%% of tweets with URLs""" % (                     stringpatterns_retweet[n], retweets[n],                     100*retweets[n]/total,                     stringpatterns_retweet[n],                     retweets_withurls[n], 100*retweets_withurls[n]/total,                     100*retweets_withurls[n]/retweets[n],                     100*retweets_withurls[n]/withurls))

2 thoughts on “This is a test: Python program in Posterous with Markdown

    Anonymous said:
    September 21, 2010 at 12:34 pm

    So this blogpost went almost right. Two corrections:"included code in the ?????? tag" should have been "included code in the ???pre??? tag"The first line in the code is indented differently that the other lines.

    Twitter retweet analysis « Finn Årup Nielsen's blog said:
    September 12, 2014 at 9:45 pm

    […] (Note 21. september 2010: I had some problems displaying the results and code on this blog homepage. I have now reedited parts of the text, and I hope my edits didn’t disturb the original message or introduced errors. For the python code see also a more recent blogpost) […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s