• R/O
  • SSH
  • HTTPS

shm-rss: Commit


Commit MetaInfo

Revision1 (tree)
Time2014-05-08 10:17:05
Authortamomo

Log Message

Import

Change Summary

Incremental Difference

--- trunk/shm.rb (nonexistent)
+++ trunk/shm.rb (revision 1)
@@ -0,0 +1,45 @@
1+#!/usr/bin/ruby
2+require 'nokogiri'
3+require 'open-uri'
4+require 'rss'
5+
6+url = "http://www.st.ryukoku.ac.jp/~kjm/security/memo/"
7+doc = Nokogiri::HTML(open(url))
8+
9+### FIXME: any better ways there?
10+doc.css('a[href^="/~kjm/"]').each do |anc|
11+ anc['href'] = "http://www.st.ryukoku.ac.jp" + anc['href']
12+end
13+
14+### Which version should we use?
15+rss = RSS::Maker.make("2.0") do |xml|
16+ xml.channel.title = doc.title
17+ xml.channel.link = url
18+ xml.channel.description = doc.css('div.NORMAL').first.children
19+
20+ doc.css('a.NU').each do |link|
21+ next if link.parent.name == "h2"
22+ i = xml.items.new_item
23+ ### a"》", span" ", content
24+ i.title = link.next.next.content
25+ i.link = link['href']
26+ if link.parent.name == "p"
27+ ### Normal short items
28+ i.description = link.parent.parent.children
29+ elsif link.parent.name == "h3"
30+ ### "various" etc
31+ i.description = link.parent.next.next
32+ else
33+ i.description = "Something wrong"
34+ end
35+ i.date = Time.parse(/#([0-9]{8})/.match(link['href'])[1])
36+ end
37+
38+ ### TTL depends on your cron settings
39+ xml.channel.ttl = "60" ### (in minutes)
40+end
41+
42+File.open("shm.rss", "w") do |f|
43+ f.write(rss.to_s)
44+end
45+
Added: svn:executable
Show on old repository browser