メインコンテンツに移動
mattz.xii.jp

Main navigation

  • Home
  • YBR125メモ
User account menu
  • ログイン

パンくず

  1. ホーム

2ちゃんねるログビューアを作成する(3)

By mattz , 2008/05/22

「㌧」のことは置いといて、(1)と(2)を組み合わせてみた。細かいことは後から考えよう。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
2ちゃんねるログを読み込んで整形してhtmlとして出力する
'''
import re
import sys
import codecs
def parseRes( res, n ):
        ar = re.split( '<>', res )
        num = str(n)
        ret = '<dt id=\'dt' + num + '\'>' + num + u': 名前:<span class="name">'
        if ar[1]:
                ret += '<a href="mailto:' + ar[1] + '">'
        ret += ar[0]
        if ar[1]:
                ret += '</a>'
        ret += '</span> ' + ar[2]
        ret += '</dt>\n<dd id=\'dd' + num + '\'>'
        ret += ar[3] + '</dd>\n'
        return ret

print 'Content-Type: text/html;charset;Shift_JIS'
print
print '''
<html>
<head><title>prototype</title>
<meta http-equiv="Content-Type" content='text/html; charset="Shift_JIS"' />
</head>
<body>
<dl>
'''
fout = codecs.getwriter('shift_jis')(sys.stdout)
log = codecs.open('1111198050.dat', 'r', 'shift_jis', 'ignore' )
res = 1;
for line in log:
        fout.write( parseRes( line, res ) )
        res += 1

print '

タグ

  • Python

最近のエントリー

  • フロントブレーキパッドの交換
  • バイクガレージを買った
  • バックミラーの交換
  • 角目化
  • バイクカバーを新調
  • クラッチレバーブーツの硬化対策
  • ハンドルストッパー
  • ジェッティングの見直し
  • バックミラーの防眩化
  • チェーン交換(その後)

ランダム

  • バンブー/マウンテン発売記念ライブに行ってきた (2010/02/13)
  • ローマの道も一歩から? (2009/03/05)
  • 高尾山薬王院火渡祭に行ってきた (2009/03/09)
  • 塊魂モバイル (2009/02/24)
  • のだめカンタービレ21 (2008/08/13)

月別アーカイブ

  • 5月 2014 (1)
  • 2月 2014 (1)
  • 12月 2013 (1)
  • 11月 2013 (1)
  • 10月 2013 (1)
  • 6月 2013 (1)
  • 5月 2013 (1)
  • 3月 2013 (2)
  • 2月 2013 (1)
  • 1月 2013 (2)
  • 12月 2012 (1)
  • 11月 2012 (1)

ページ送り

  • 前ページ
  • 4
  • 次ページ
RSS feed