エントリィ追加時に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
エラー無視。
Amazon.co.jpの書籍ページのリンクを生成する。
<p>amazon::ISBN-13</p>
|
涼宮ハルヒの分裂 (角川スニーカー文庫 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検索のリンクを生成する。
<p>google::検索語</p>
"""
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("&", "&")
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()
])
詳細は laclefwikiのreStructuredText記法 参照。
最初の行がblosxomTitle(h2)になる。以下で見出しを設定するとh3、h4、h5になる。
preは、::<改行><空行><インデント>Text
ここはプレーンテキスト #!/usr/local/bin/python
blockquoteは、<インデント>Text
ここは引用テキスト
ul/liは、*/+/-
ol/liは、<NUM>.
dl/dt/ddは、DT<改行><インデント>DD
脚注は、参照元は [<NUM>/#/*/Label]_ or `Label`_ で、参照先は .. [<NUM>/#/*/Label] Text
参照元 [1]
| [1] | 参照先 |
リンクは、参照元は `Label`_ で、参照先は .. _Label: <URL>
画像は、.. image:: <URL> or 参照元で |Label| で 参照先で .. |Label| image:: <URL>
強調は、*em*、**strong**
em strong
表は、-/+/=/|で罫線を書く
| test | Label |
|---|---|
| body1 | body2 |
フィールドテキストは、:Label: Text
| ラベル: | テキスト |
|---|
水平線は、-を4つ以上並べる
エスケープは、\/``Text``など