Outer Web Thought Log
March 04, 2003
Sam goes Python (again)
In a rather successful attempt to learn us whining Python newbies how cool scripting languages really can be, Sam has posted a screen-long (!) 3-pane RSS feed aggregator. Which seriously tickles me that I really should start hacking on my own blogging tool, now that MozBlog decided to stop functioning under Moz1.3b, and I'm getting sick at typing HTML inside a text pane.
Funny to see how expressive scripting languages can be without falling into the modem-noise-trap of Perl. I remember Tom and I discussing how we could easily create referrer logs for our blogs on Friday, and both of us arriving on Monday with 'our' solution. While his likely will be better and more extensible (Java, of course), mine was only a few lines of Python code (underneath, don't laugh).
#!/usr/bin/python2
import re, time
from string import find

def compareandreversereflist(item1, item2):
    if item1[1] > item2[1]:
        return (-1)
    elif item1[1] == item2[1]:
        return (0)
    else:
        return (1)


pattern = re.compile(r'^((?:\d+\.?){4}) \S \S \[(.*?)\] \"\S+ (\S+) \S+" \d{3} - \"(.*?)\" \".*?\"$')

logfile = open('/logs/blogs.cocoondev.org/http/access_log', 'r')

referrers = {}

for line in logfile.readlines():
    linematch = re.match(pattern, line)
    if linematch:
        refmatch = str(linematch.group(4))
        pathmatch = str(linematch.group(3))
        if find(pathmatch,'/stevenn/') != -1:
            if refmatch != '-':
                if find(refmatch,'http://blogs.cocoondev.org/stevenn/') == -1:
                    if not(referrers.has_key(refmatch)):
                        referrers[refmatch] = 1
                    else:
                        referrers[refmatch] = referrers[refmatch] + 1

list = referrers.items()

list.sort(compareandreversereflist)

print """<html>
    <head>
        <title>Referrer report</title>
    </head>
    <body>
        <h1 align="center">Referrer report</h1>
        <hr>
        <ul>"""

for item in list:
    print '            <li><a href="' + item[0] + '">' + item[0] + '</a>: ' + str(item[1]) + '</li>'

print """        </ul>
        <hr>"""

print '        <p align="center">Generated on ' + time.ctime(time.time()) + '</p>'

print """    </body>
</html>"""
Hm... How difficult should it be to embed that infamous IE RichText/HTML editing thingy into a wxPython app?
Posted by stevenn at March 4, 2003 05:39 PM ()
Comments

It's not hard to embed the IE WebBrowser control into a wxPython app. In fact, one of the wxPython demos does it for you already ;-)

(You need to set the document.designMode field to "On" yourself if you want to use it as an editor rather than a browser, but that's not a lot of work).

Posted by: Phillip Pearson at March 6, 2003 04:31 AM