forked from id774/automaticruby
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfeed_parser.rb
More file actions
51 lines (47 loc) · 1.38 KB
/
feed_parser.rb
File metadata and controls
51 lines (47 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
# Name:: Automatic::FeedParser
# Author:: 774 <http://id774.net>
# Created:: Feb 19, 2012
# Updated:: Feb 26, 2014
# Copyright:: Copyright (c) 2012-2014 Automatic Ruby Developers.
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
module Automatic
module FeedParser
require 'rss'
require 'uri'
require 'nokogiri'
def self.get_url(url)
begin
unless url.nil?
Automatic::Log.puts("info", "Parsing Feed: #{url}")
feed = URI.parse(url).normalize
open(feed) {|http|
response = http.read
RSS::Parser.parse(response, false)
}
end
rescue => e
raise e
end
end
def self.parse_html(html)
RSS::Maker.make("2.0") {|maker|
xss = maker.xml_stylesheets.new_xml_stylesheet
maker.channel.title = "Automatic Ruby"
maker.channel.description = "Automatic::FeedParser"
maker.channel.link = "https://github.com/automaticruby/automaticruby"
maker.items.do_sort = true
doc = Nokogiri::HTML(html)
(doc/:a).each {|link|
unless link[:href].nil?
item = maker.items.new_item
item.title = "Automatic Ruby"
item.link = link[:href]
item.date = Time.now
item.description = ""
end
}
}
end
end
end