`

Hemidemi群組最新書籤 -- Console版

阅读更多
哇哇哇
http://flickr.tw的站長推出這麼棒的Hemidemi hacking...
只是小弟遜咖,沒辦法像他那樣>"<
好吧.. 我只好寫個個人用的小工具
這個程式是適用於群組的,一般來說群組都會有最新書籤,而這個是將最新書籤印出來的..
程式只能跑在純文字模式下..
輕巧咩~另外網管如果沒有在管沒有X Window的主機時,也可以用這個拉!
Usage: $ ./grp_recent.rb group_name [count]
Options: * group_name: 沒錯!就是群組名稱!
* count: 可省略參數,用於顯示幾個書籤(從最新的開始算起,預設是6個)
程式碼如下:
#!/usr/bin/env ruby
# Code by CFC <at> Zuso Security</at>
# Taiwan Ruby Users Group: http://www.ruby.oss.tw/
# Rails Taiwan: http://www.rubyonrails.org.tw/
#
require 'rexml/document'
require 'open-uri'
include REXML

class Recent
attr_accessor :grp_name, :channel, :items

def initialize(grp_name, count)
@grp_name = grp_name
@url = "http://www.hemidemi.com/rss/group/#{@grp_name}/bookmark/recent.xml"
@channel = @channel || {}
@items = []
if count == nil
@count = 6
else
@count = count.to_i
end
end

def run
load_in
show
end
def load_in
open(@url) do |f|
xml = Document.new(f.read)

xml.elements.each("*/channel") do |chnl|
@channel["name"] = chnl.elements["description"].text
@channel["link"] = chnl.elements["link"].text
end

xml.elements.each("*/channel/item") do |item|
itm = {}
itm["title"] = item.elements["title"].text
itm["description"] = item.elements["description"].text
itm["link"] = item.elements["link"].text
itm["creator"] = item.elements["dc:creator"].text
@items << itm
end
end
end

def show
puts "="*10
puts "群組:#{@channel["name"]} [ #{@channel["link"]} ]"
puts "共有#{@items.size}個書籤"
puts "="*10
@count = @items.size if @items.size < @count
@count.times { |cnt|
puts "張貼者:#{@items[cnt]["creator"]} [ http://www.hemidemi.com/user/#{@items[cnt]["creator"]}/home ]"
puts "標題:#{@items[cnt]["title"]}"
puts "網址:#{@items[cnt]["link"]}"
puts "敘述:#{@items[cnt]["description"]}"
puts "*"*10
}
puts "="*10
end
public :run
private :load_in, :show
end

rss = Recent.new(ARGV[0], ARGV[1])
rss.run

下載點:http://stmail.tajen.edu.tw/~593092514/grp_recent.rb

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics