laclefblog logo

Mon, 16 Apr 2007

更新PING

エントリィ追加時にXML-RPCで更新PINGを送信する。

必要なのは、エントリィのタイトルとPermanent Link。

import xmlrpclib
servers = ['http://blogsearch.google.co.jp/ping/RPC2',
           'http://api.my.yahoo.com/RPC2',
           'http://r.hatena.ne.jp/rpc',
           'http://www.bloglines.com/ping',
           'http://rpc.weblogs.com/RPC2'
           'http://rpc.reader.livedoor.com/ping',
           'http://rpc.technorati.com/rpc/ping',
           'http://blog.goo.ne.jp/XMLRPC',
           'http://bulkfeeds.net/rpc',
           'http://ping.ask.jp/xmlrpc.m',
           'http://ping.bloggers.jp/rpc/',
           'http://ping.cocolog-nifty.com/xmlrpc',
           'http://ping.fc2.com',
           ]
for s in servers:
    rpcs = xmlrpclib.Server(s)
    try:
        resp = rpcs.weblogUpdates.ping(title, permalink)
    except:
        continue

エラー無視。

Sun, 15 Apr 2007

Amazonリンク生成プラグイン

Amazon.co.jpの書籍ページのリンクを生成する。

<p>amazon::ISBN-13</p>
谷川 流 - 涼宮ハルヒの分裂 (角川スニーカー文庫 168-9)

涼宮ハルヒの分裂 (角川スニーカー文庫 168-9)
谷川 流

"""
Amazon Link Generator powered by Amazon Web Service

To install:
 1) Put nospam.py in your plugin directory.
 2) In config.py add nospam to py['load_plugins']
 3) Add the following variables to config.py:
    py['amazon_access_key'] = 'Your Amazon Access Key' # required, no default
    py['amazon_associate_id'] = 'laclefblog-22' # optional, this is the default

To use:
 Write "<p>amazon::isbn-13</p>" on head of line.
"""

__authotr__ = "SAEKI Yoshiyasu"
__version__ = "1.0"
__url__ = "http://saekiyoshiyasu.org/"
__description__ = "Amazon.co.jp Link generator"

import urllib
import xml.dom.minidom

amazon_template = """
<table class="pyamazon">
 <tr>
  <td valign="top">
   <a href="%(link)s">
    <img src="%(img)s" title="%(author)s - %(title)s"
     alt="%(author)s - %(title)s" /></a>
  </td>
  <td>
   <p>
    <span class="title">%(title)s</span><br />
    <span class="author">%(author)s</span>
   </p>
  </td>
 </tr>
</table>
"""

def make_amazon(line, aws_access_key, aws_asso_id):
    if not line.startswith("<p>amazon::"):
        return line
    line = line.split("::")
    isbn = line[1].replace("</p>", "")
    request_url = 'http://webservices.amazon.co.jp/onca/xml'
    option_list = urllib.urlencode({
        'Service': 'AWSECommerceService',
        'AWSAccessKeyId': aws_access_key,
        'AssociateTag': aws_asso_id,
        'Operation': 'ItemLookup',
        'IdType': 'ISBN',
        'ItemId': isbn,
        'SearchIndex': 'Books',
        'ResponseGroup': 'Request,Small',
        'Version': '2007-01-15',
        })
    response_string = urllib.urlopen(request_url, option_list).read()
    res_doc = xml.dom.minidom.parseString(response_string)
    res_asin, res_title, res_author, res_link = map(
        lambda param: res_doc.getElementsByTagName(param).item(0).firstChild.data,
        ['ASIN', 'Title', 'Author', 'DetailPageURL']
        )
    img = "http://images.amazon.com/images/P/" + res_asin + ".01.TZZZZZZZ.jpg"
    return amazon_template % {"author": res_author, "title": res_title,
                              "img": img, "link": res_link}

def cb_story(args):
    request = args["request"]
    config = request.getConfiguration()
    aws_access_key = config.get('amazon_access_key')
    aws_asso_id = config.get('amazon_associate_id', 'laclefblog-22')
    data = request.getData()
    contenttype = data["content-type"]
    entry = args["entry"]
    body = entry["body"]
    if body.find('amazon::') != -1:
        entry["body"] = "\n".join([
            make_amazon(m, aws_access_key, aws_asso_id) for m in body.splitlines()
            ])

Googleリンク生成プラグイン

Google検索のリンクを生成する。

<p>google::検索語</p>

Google: Python Pyblosxom

"""
Google Link Generator

To install:
 1) Put nospam.py in your plugin directory.
 2) In config.py add nospam to py['load_plugins']

To use:
 Write "<p>google::search phrase</p>" on head of line.
"""

__authotr__ = "SAEKI Yoshiyasu"
__version__ = "1.0"
__url__ = "http://saekiyoshiyasu.org/"
__description__ = "Google Link generator"

import urllib

google_template = """
<p>
<a href="http://www.google.com/search?%(query)s">
Google: %(str)s</a></p>
"""

def make_google(line, encoding, lang):
    if not line.startswith("<p>google::"):
        return line
    line = line.split("::")
    str = line[1].replace("</p>", "")
    query = urllib.urlencode({
        'q': str,
        'hl': lang,
        'lr': 'lang_' + lang,
        'ie': encoding,
        'oe': encoding,
        }).replace("&", "&amp;")
    return google_template % {"query": query, "str": str}

def cb_story(args):
    request = args["request"]
    config = request.getConfiguration()
    encoding = config.get('blog_encoding', 'utf-8')
    lang = config.get('blog_language', 'ja')
    data = request.getData()
    contenttype = data["content-type"]
    entry = args["entry"]
    body = entry["body"]
    if body.find('google::') != -1:
        entry["body"] = "\n".join([
            make_google(m, encoding, lang) for m in body.splitlines()
            ])
Sat, 14 Apr 2007

TODO

  • permanent link で表示されないのを何とかする -> flavours/comment* を外すと解決
    • comments/trackback がおかしいのを何とかする: 匿名メールフォームにするか
  • Twitterのバッジ貼り付けを embed から object に変更する
Mon, 02 Apr 2007

PyblosxomでのreStructuredText記法

詳細は laclefwikiのreStructuredText記法 参照。

最初の行がblosxomTitle(h2)になる。以下で見出しを設定するとh3、h4、h5になる。

Title1

Title2

Title3

preは、::<改行><空行><インデント>Text

ここはプレーンテキスト
#!/usr/local/bin/python

blockquoteは、<インデント>Text

ここは引用テキスト

ul/liは、*/+/-

  • リスト1
  • リスト2
    • リスト2.1
      • リスト2.1.1
  • リスト3

ol/liは、<NUM>.

  1. リスト1
  2. リスト2
  3. リスト3

dl/dt/ddは、DT<改行><インデント>DD

定義
定義テキスト

脚注は、参照元は [<NUM>/#/*/Label]_ or `Label`_ で、参照先は .. [<NUM>/#/*/Label] Text

参照元 [1]

[1]参照先

リンクは、参照元は `Label`_ で、参照先は .. _Label: <URL>

画像は、.. image:: <URL> or 参照元で |Label| で 参照先で .. |Label| image:: <URL>

/pyb/flavours/html.flav/logos/myyahoo.gif

強調は、*em*、**strong**

em strong

表は、-/+/=/|で罫線を書く

test Label
body1 body2

フィールドテキストは、:Label: Text

ラベル:テキスト

水平線は、-を4つ以上並べる


エスケープは、\/``Text``など