Python Blog

Continuing my whirlwind tour through scripting languages, Here are the main parts of my site generator redone in Python:

Site Generation

entries = os.listdir(".")

posts = ""
for e in entries:
  cmd = "markdown %s" % e
  post = os.popen(cmd).read()
  date = e

  post_html = template_post % (date,date,post)
  posts += post_html

main_page = template_master % posts

print main_page

Table of Contents

#!/usr/bin/env python

import os
import sys
import re

output = []
for arg in sys.argv:
    with open(arg) as f:
        for line in f:
            if (re.search(r"^###", line)):
                date = arg
                line = re.sub(r"### ", "", line)
                line = re.sub("\n", "", line)
                output_line = '<a href="index.html#%s">%s</a><br>' % (date, line)
                output += [output_line]

for line in output:
    print line

Python SimpleHTTPServer

Also serving the site using the below code utilizing Python’s included SimpleHTTPServer package.

import SimpleHTTPServer
import SocketServer
import os
import grp
import sys

PORT = int(sys.argv[1])
user = int(sys.argv[2])
group = int(sys.argv[3])

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)


print "dropped privileges to user: %s group: %s" % (os.getuid(), os.getgid())
print "Serving at port", PORT

Favorite Programming Languages

Currently the list of languages that I am most attracted to is:

  • C
  • Go
  • Perl
  • Erlang
  • JavaScript

This is different from the languages that I would actually claim to be somewhat competent in:

  • C (would like to be more so)
  • Awk
  • Tcl
  • Python
  • JavaScript
  • PHP (somewhat)

I feel like I’m becoming competent in Perl, and I am working to become competent in C# and possibly F# since those are languages that are used or potentially used at work.

Emacs Setup

Setting up yet another emacs instance:

Here are the entries in .emacs that I have to have:

(setq-default indent-tabs-mode 'nil)
 (global-set-key [(control h)] 'delete-backward-char)

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s