个人工具
您位于: 首页 资源中心 原始部落 13109 Hi, Planet!

Hi, Planet!

by YangHong posted on 2006-12-16 18:28 last modified 2006-12-16 20:42 —

我来啦!下载 planet,添加自动从 wiki 页面更新的 RSS 源的脚本,加入 crontab 自动运行,定制 planet 页面,显示自定义 logo。

Planet 你好!

www.planetplanet.org 提供的 planet 只能通过编辑一个配置文件(config.ini)来添加新的 Blog 源,并通过 crontab 执行一个 python 脚本来从各个 RSS 源更新 planet 网页内容。

为了方便添加新的 RSS 源,我写了一个脚本,用来从 wiki 面页中获取 RSS 源列表,并自动更新到 planet 配置文件中。然后再执行 planet 更新脚本。

$ cat planet-gen-rss.sh 
#!/bin/bash
#
# Author: YangH
#
# Auto grab rss source from wiki page and update config.ini of planet.
#
# wiki page format:
#
# ---separator---
#
# <Author name> <Blog RSS> [Logo url]
#
# ---separator---
#

conf="gnome-cn/config.ini"
tmpf=`mktemp /tmp/rss-source.XXXXXX`
srcurl="http://www.gnome-cn.org/documents/wiki/GnomecnPlanet/src"

#echo $tmpf
wget -q $srcurl -O $tmpf
sed -i '1,/^---separator---/d;/^---separator---/,$d;/^$/d' $tmpf

tmprss=`mktemp /tmp/rss-tmp.XXXXXX`
awk '{if ($1 != "" && $2 != "") print "["$2"]\nname = "$1""; if ($3 != "") print "logo = "$3; print ""}' $tmpf > $tmprss

cp -f $conf ${conf}.bak
sed -i '/^#---separator---/,$d' $conf
echo "#---separator---" >> $conf
cat $tmprss >> $conf

#cat $conf

# clean up
rm -f $tmpf $tmprss

另外,为了在 planet 中显示 logo 图标,还需要改一下模板,

--- examples/fancy/index.html.tmpl      2006-05-09 12:00:27.000000000 -0400
+++ gnome-cn/index.html.tmpl 2006-12-16 19:32:20.000000000 -0500
@@ -53,8 +53,11 @@
<TMPL_IF channel_face>
<img class="face" src="images/<TMPL_VAR channel_face ESCAPE="HTML">" width="<TMPL_VAR channel_facew
idth ESCAPE="HTML">" height="<TMPL_VAR channel_faceheight ESCAPE="HTML">" alt="">
</TMPL_IF>
+<!-- Hacked by yh -->
+<TMPL_IF channel_logo>
+<img class="face" src="<TMPL_VAR channel_logo ESCAPE="HTML">" width="<TMPL_VAR channel_logowidth ES
CAPE="HTML">" height="<TMPL_VAR channel_logoheight ESCAPE="HTML">" alt="">
+</TMPL_IF>
</TMPL_IF>
-

<div class="entrygroup" id="<TMPL_VAR id>"<TMPL_IF channel_language> lang="<TMPL_VAR channel_langua
ge>"</TMPL_IF>>
<TMPL_IF title>

好了,运行 ./planet.py gnome-cn/config.ini 重新生成一下。就可以看到带 logo 图标的页面了。

为了让 planet.py 定时执行,把它写入 crontab 吧。

使用 crontab -e 命令添加:

$ crontab -l
# m h dom mon dow command
* */1 * * * /home/gnome/planet/planet-cron.sh

$ cat planet-cron.sh
#!/bin/bash
cd /home/gnome/planet

# generate rss source from wiki page
./planet-gen-rss.sh

# renew rss
./planet.py gnome-cn/config.ini >> gnome-cn/html/planet.log

就这些, planet.gnome-cn.org 全新上线了。:)

全部代码都存倒仓库中了: https://svn.gnome-cn.org/repos/gnome-cn/trunk/planet/

把自动生成的 rss-source.txt 也加入到仓库中,以防 wiki 内容被破坏后 rss 源数据丢失。

文档操作
13109
« 十二月 2008 »
十二月
1234567
891011121314
15161718192021
22232425262728
293031
最近帖子:
Blog Entry Test simple blog 3.0beta
更多...
分类:
GTK+/GNOME (0)
开源社区 (0)
自由桌面 (0)
本 站 赞 助 商
北京红旗中文贰仟