簡介
此 Plugin 讓你在 blog 上顯示你的 Flickr 最新照片。我覺得 unserialize() 應該會比解析 XML 快得多,所以我寫了這個 plugin.
安裝
- 解壓縮檔案。
- 將 flickrfeed 資料夾放到 /user/plugins 資料夾中,然後到 Habari 管理介面中啟用它。
將下面這行貼到你的 Theme 中。
<?php if ( Plugins::is_loaded('FlickrFeed') ) $theme->flickrfeed(); ?>
設定 / 自訂
啟用後,請按下 Configure 來設定此 Plugin ,有這些項目可以設定:
- Photostream type
- Flickr ID – 你的 Flickr ID ,你可以使用 idGettr 取得。
- № of photos – 設定要顯示幾張照片。
- Photo size – 設定照片大小。
- Tags – 限制只顯示某些標籤的照片,以逗號分隔,不可空白。(可不填)
- Cache expiry – 設定暫存檔保存多久,單位是秒。
如果你要修改 HTML 呈現的結果,可以將 flickrfeed.php 複製到你的 Theme 資料夾中並修改這個檔案。
下載
更新紀錄
Introduction
This plugin show your latest photos on your blog. I write this plugin because I think unserialize() should be much faster than parsing XML.
Installation
- Extract the file.
- Put the folder ‘flickrfeed’ to /user/plugins and activate it.
Copy and paste the following line to your theme.
<?php if ( Plugins::is_loaded('FlickrFeed') ) $theme->flickrfeed(); ?>
Configuration & Customization
After activated it, click Configure button to setup the plugin.
- Photostream type
- Flickr ID – Place your Flickr ID here, you can get your Flickr ID from idGettr.
- № of photos – Number of photos to be shown.
- Photo size
- Tags – A comma delimited list of tags to filter the photos by.
- Cache expiry – Number of second after the call that the cache will expire.
You can copy ‘flickrfeed.php’ to your theme directory and modify the HTML output.
Download
Changelog
- 0.2 (2008-07-26) – Initial release.
Jaiku 0.3.1 更新了處理要求逾時及非預期的回應(通常發生於 Jaiku 伺服器錯誤時)。
Jaiku 0.3.1 update for better handling request timeout or unexpected response.
GAEO 預設有幾種繞徑方式,官方文件如是說:
/ 代表呼叫 {'controller':'welcome', 'action':'index'}
/foo/bar 代表呼叫 {'controller':'foo', 'action': 'bar'}
/foo 代表呼叫 {'controller':'foo', 'action':'index'}
如果你也是用 gaeogen.py 產生出基本架構的話,那就還有:
/foo/bar/blah 代表呼叫 {'controller':'foo', 'action': 'bar', 'id': 'blah'}
官方文件中的範例跟使用 gaeogen.py 產生出的架構相同,但沒有說要怎麼取得 Controller 、 Action 和 ID ,在下對於 Python 不熟,所以又是試了一段時間才成功。
Controller 應該不用再次介紹,用 gaeogen.py 產生出來便是。Action 是指 Controller 中的 function 名稱,舉例來說, index 就是一個 Action 。
class MyController(BaseController):
def index(self): # 我就是 Action 啦!
pass
接下來的問題是要怎麼取得 ID ,我 trace 原始碼 trace 了很久(因為我是新手嘛!),才知道原來用 self.params.get('id') 便能取得。此外也可以用 self.params['id'] ,但這個方法在沒有 ID 時會發生錯誤。以下給一份完整的範例,此範例的用途是將Yahoo!奇摩字典的 Auto-completion 轉換為 Firefox 可用的 OpenSearch Suggestions 格式。
import cgi
from gaeo.controller import BaseController
from google.appengine.api import urlfetch
class YdictController(BaseController):
def index(self):
pass
def lookup(self):
p = cgi.escape(self.params['id']) if 'id' in self.params else ''
try:
result = urlfetch.fetch('http://ws.dict.tpe.yahoo.com/suggest_data.php?of=js&p=' + p, method="GET")
if result.status_code == 200 and result.content.startswith('fxsearch([') and result.content.endswith('])'):
suggestions = result.content[9:-1]
self.render(text=suggestions)
except:
pass
成果:http://bcse.appspot.com/ydict/lookup/sugges
等我試出來後,突然想到了什麼,便去查 RoR 的文件…… 果不其然,這取用方法跟 RoR 好像啊~ 看來在 GAEO 缺乏文件的現在,或許也能先參考 RoR 的文件…… XD
大概只有像我這樣的 Python 超新手才會有這個問題 XD
在 GAEO 中建立 Model 的流程如下:
- 在
application 資料夾中新增一個 model 資料夾
- 在
model 資料夾中新增兩個檔案 __init__.py 、 my_model.py
__init__.py 保持空白就可以,在 my_model.py 中則可以寫你要的 Model,舉例如下:
from google.appengine.ext import db
from gaeo.model import BaseModel
# 本範例中沒用到 BaseModel 新增的功能,所以也可刪去這行
class User(BaseModel): # 如果不用 BaseModel,就必須改為繼承 db.Model
user = db.UserProperty(required=True)
nickname = db.StringProperty(required=True)
email = db.EmailProperty(required=True)
接下來重點來了!在 my_controller.py 中要怎麼引用這個 Model 呢?
from model import my_model
順便筆記一下遍歷的方法
users = my_model.User.all()
# 我覺得既然用了 DataStore (BigTable),就不要再用 GQL 作查詢
# 實際上這種寫法也比較容易閱讀
for user in users:
print user.nickname
雖然放假了,我還是滿常來 Lab 的,這兩天的主要內容是研究 Google App Engine ,進度從安裝、「Hello World!」、以 Google Account 作身分認證,一直到使用 Datastore API ,然後上 PTT 發現有人把功能很完整的 Ikariam 物資交易平台做好了,讓我又失去了我的題目1 XD
雖然如此,但作一下最近的筆記。
安裝 Python 、 Google App Engine 及 GAEO
- 下載 Google App Engine SDK 及 Python 2.5。
- 以上兩個都是照著指示按「下一步」就能裝好。
- 下載 GAEO,然後解壓縮到任何你喜歡的地方。
- 在我的電腦上按右鍵→內容→進階→環境變數。然後在 PATH 的最後加上
;C:\Python25;D:\Documents\htdocs\gaeo\bin ←此為範例,請根據你將 Python 、 GAEO 安裝在哪裡而修改。至於 Google App Engine SDK 則會自動幫你加上,不用我們動手。
建立一個新的專案
- 在你喜歡的資料夾中,以命令提示字元執行
gaeo.py project_name ,GAEO 就會幫你建立好 project_name 資料夾以及基本的程式與資料夾結構。
- 然後在
project_name 資料夾中,以命令提示字元執行 dev_appserver.py --port=8080 . 2,這樣就能將程式執行起來,你可以在 http://127.0.0.1:8080/ 看到結果,看見 “It works!!” 就表示成功了。這個畫面的程式位於 project_name/application/controller/welcome.py ,而 template 位於 project_name/application/templates/welcome 資料夾中。
建立新的 Controller
- 在
project_name 資料夾中,以命令提示字元執行 gaeogen.py controller Say 這樣會在 project_name/application/controller 中建立一個 say.py ,其中就是新的 Controller ,名為 SayController ;此外也會建立一個 project_name/application/templates/say 資料夾,內容是空的,留待未來使用。
上傳到 Google App Engine
- 這邊我實在得說 Google 包裝得很好,只要在
project_name 資料夾中,以命令提示字元執行 appcfg.py update .3 ,程式便會傳上去,並且會自動編版號。
其他
- 以 Google Account 作身分認證同樣很簡單,基本上照著 Google 的教學文件作就沒錯了,只不過在本機端測試時它不需要真的登入,只會出現一個看起來怪怪的登入畫面,這並不是你作錯了。
- 有時候程式發生問題時,會噴 Error 404 而不給錯誤訊息,我目前還不知道 Python 有什麼簡單的 debug 方式…
- 目前 GAEO 的
gaeogen.py 只能用來生成 Controller ,所以我不知道 Model 應該放在哪裡…
- 在編輯工具方面我試了 Eclipse 及 UliPad , Eclipse 看得出來是一個功能非常強大的 IDE ,
但我不知道怎麼將它和 GAEO 整合在一起4;而 UliPad 有些功能不符合我的習慣,它的 Auto-completion 則是基於「本檔案中曾使用過的函式」,對我來說沒什麼幫助,最後還是用回 EmEditor。