唐诗宋词API

  • 数据源:全唐诗,全宋词,网络
  • 唐诗:42863首
  • 宋词:17758首

1 API说明

唐诗宋词API每次调用随机返回一首

1.1 url

1.2 参数

1.3 举例

1.3.1 返回json格式

url: http://gxy.me/tangshi?format=json
res = {
"vol": 539,
"ch": 107,
"title": "桂林路中作",
"author": "李商隐",
"lines": [
"地暖无秋色,江晴有暮晖。空馀蝉嘒嘒,犹向客依依。",
"村小犬相护,沙平僧独归。欲成西北望,又见鹧鸪飞。"
]
}

1.3.2 返回文本格式

  url: http://gxy.me/tangshi
  res = 
	  题德玄上人院
	    杜荀鹤

刳得心来忙处闲,闲中方寸阔于天。浮生自是无空性,
长寿何曾有百年。罢定磬敲松罅月,解眠茶煮石根泉。
我虽未似师披衲,此理同师悟了然。

1.3.3 配合cowsay

gxy@local:~$ wget -q -O- http://gxy.me/songci | cowsay
gxy@local:~$ curl -s http://gxy.me/songci | cowsay
gxy@local:~$ wget -q -O- http://gxy.me/tangshi | cowsay
gxy@local:~$ curl -s http://gxy.me/tangshi | cowsay
gxy@local:~$ wget -q -O- http://gxy.me/shici | cowsay
gxy@local:~$ curl -s http://gxy.me/shici | cowsay
 ____________________________
/  好事近(代人书扇)        \

| 杨冠卿                     |
|                            |
| 晚起倦梳妆,斜压翠鬟云鬓   |
| 手捻花枝辄笑,问青鸾音信   |
| 绣帘慵卷玉钩垂,风篁奏余韵 |
\ 灯火黄昏院落,报雕鞍人近   /
 ----------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
gxy@local:~$

1.3.4 配合xcowsay

gxy@local:~$ wget -q -O- http://gxy.me/songci | xcowsay -t 0
gxy@local:~$ curl -s http://gxy.me/songci | xcowsay -t 0
gxy@local:~$ wget -q -O- http://gxy.me/tangshi | xcowsay -t 0
gxy@local:~$ curl -s http://gxy.me/tangshi | xcowsay -t 0
gxy@local:~$ wget -q -O- http://gxy.me/shici | xcowsay -t 0
gxy@local:~$ curl -s http://gxy.me/shici | xcowsay -t 0

2 emacs 文艺牛

在~/.emacs.d/init.el中增加如下代码,每次emacs启动是文艺牛会赋诗一首,按 g 刷新。

(defun literary-cow-refresh ()                                                        
  "refresh a new literary cowsay text"                                                
  (interactive)                                                                       
  (with-current-buffer "literary-cow"                                                 
    (read-only-mode -1)                                                               
    (erase-buffer)                                                                    
    (setq text (shell-command-to-string "wget -q -O- http://literary-cow.cc/songci | cowsay")) 
    (insert  text)                                                                    
    (read-only-mode)))                                                                

(defun literary-cow-init ()                                                           
  "Init literary cow"                                                                 
  (interactive)                                                                       
  (get-buffer-create "literary-cow")                                                  
  (with-current-buffer "literary-cow"                                                 
    (local-set-key "g" 'literary-cow-refresh)                                         
    (literary-cow-refresh)))                                                          

(setf initial-buffer-choice                                                           
      (lambda ()                                                                      
	(literary-cow-init)                                                           
	(switch-to-buffer "literary-cow")))