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

Main navigation

  • Home
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
前のエントリー次のエントリー

最近のエントリー

  • 2025シーズン セ・パ12球団の総移動距離
  • 2023年度 パシフィック・リーグ主催試合ヒーローインタビューランキング
  • 2024シーズン セ・パ12球団の総移動距離
  • 当サイトのDrupalが10になりました
  • E-Vinoを買ってみました
  • 2023シーズン セ・パ12球団の総移動距離
  • 俺は野球殿堂博物館を甘く見ていた
  • 2022シーズン セ・パ12球団の総移動距離
  • Drupalを9にあげてみました
  • 2021シーズン セ・パ12球団の総移動距離
RSS feed