Douban provider for Alexandria

Alexandra is a desktop book collection manager on gnome written in ruby. With an extensible architecture, Alexandria uses different sources to retrieve book’s data, including Amazon and many local sites.

Douban.com is considered to be most applicable data source for books published in Chinese. So I write this provider according to Alexandria’s SPI. Now it’s possible to add Chinese books and manage reading lists.

alexandria

Now the code can be found in Alexandria’s bug tracker:
http://rubyforge.org/tracker/index.php?func=detail&aid=28160&group_id=205&atid=865

However, the patch file of book_providers.rb in that list is for svn trunk head version only. To use it with currently stable version of Ubuntu, first, make sure you have Alexandria version 0.6.5-0ubuntu1 and libjson-ruby1.8 installed.

Download douban.rb from rubyforge:
http://rubyforge.org/tracker/download.php/205/865/28160/4923/douban.rb
Copy the file to /usr/lib/ruby/1.8/alexandria/book_providers/ with super user privileges.
Use this patch to /usr/lib/ruby/1.8/alexandria/book_providers.rb

310a311,323
<     begin
<       begin
<         require 'json'
<       rescue LoadError
<         require 'rubygems'
<         require 'json'
<       end
<       require 'alexandria/book_providers/douban'
<     rescue LoadError =< ex
<       log.error{ex}
<       log.warn {'Fail to load douban as provider'}
<     end
<

Feel free to report issue here.

在苏州河

今天又到苏州河附近拍,发现在四川路桥对面的邮政博物馆楼顶拍浦东效果甚佳,闹中取静。另外在河南中路和宁波路路口有一家小杨生煎店,人相对其他地方比较少。

DSC_0015
DSC_0021
DSC_0022
DSC_0023
DSC_0055
DSC_0067
DSC_0078
DSC_0079
DSC_0082
DSC_0084
DSC_0085
DSC_0091

最后一张景不错,不过拍得曝光过度了,处理了一下
DSC_0054

My First Hello World Web App Using Compojure

Compojure是一个用Clojure写成的类似Sinatra的Web框架。Leiningen是一个新的Clojure构建工具,它用Maven来处理依赖管理,而通过封装Lancet(基于Ant)来实现build-in的task。

以上是背景介绍。以下是HelloWorld。

创建一个目录作为工程目录

mkdir compojure-app
cd compojure-app

像创建build.xml和pom.xml一样创建project.clj

(defproject info.sunng/compojure-app "0.0.1"
        :description "A demo app running on compojure framework"
        :dependencies [[org.clojure/clojure "1.1.0"]
                        [org.clojure/clojure-contrib "1.1.0"]
                        [compojure "0.3.2"]]
        :dev-dependencies [[leiningen/lein-swank "1.1.0"]]
        :main info.sunng.compojureapp.helloworld)

首行定义了项目的groupId, artifactId和version,其后的是maven风格的依赖定义,最后我们还定义了程序的主类。

这个helloworld只有一个文件,被放在src/info/sunng/compojureapp/目录下

(ns info.sunng.compojureapp.helloworld (:gen-class) (:use compojure))

(defroutes example-routes
    (GET "/" "Hello W0rld")
    (ANY "*" [404 "Page Not Found"]))

(defn -main []
    (run-server {:port 8080} "/*" (servlet example-routes)))

中间就是Sinatra风格的URL映射定义,最后在主类中通过一个run-server方法以嵌入式的方式运行一个jetty

回到工程目录,执行构建

lein deps
lein compile
lein uberjar

通过uberjar可以将依赖通通打入一个jar包中,接着就可以通过
java -jar compojure-app-standalone.jar
启动你的Web程序了,很酷吧

除了这种方式,还可以通过
lein swank
启动一个swank server(project.clj中定义了dev-dependency),再用Emacs的SLIME交互式地运行程序。

参考