feedparser 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +0 -2
- data/README.md +20 -7
- data/lib/feedparser.rb +0 -2
- data/lib/feedparser/parser.rb +1 -8
- data/lib/feedparser/version.rb +1 -1
- data/test/helper.rb +4 -4
- metadata +1 -4
- data/lib/feedparser/helper/atom_v03.rb +0 -66
- data/test/test_atom_v03.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 747fe0251bd3069a2c17b9ef047673386410b314
|
4
|
+
data.tar.gz: 2d5e9a169f84b90e3fd5b66c4b614e5b57adc82e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4042d15f3212979e796b7e979acf27f8da6d19fa8105580649d7bd8239f3f73620a0b99ec7254b11f6a77f3e7db10abe7b87126f10551265c6e8574ba1b62efa
|
7
|
+
data.tar.gz: 1b1545a13e22c2320020d32b3d4a7a817c6d22d692df9d5a72c70cb1cb6a383cc12d59f279f9ef5734034f17f9a8169561db8d263cfa2c56471dfdd964ecb80e
|
data/Manifest.txt
CHANGED
@@ -6,7 +6,6 @@ lib/feedparser.rb
|
|
6
6
|
lib/feedparser/builder/atom.rb
|
7
7
|
lib/feedparser/builder/rss.rb
|
8
8
|
lib/feedparser/feed.rb
|
9
|
-
lib/feedparser/helper/atom_v03.rb
|
10
9
|
lib/feedparser/item.rb
|
11
10
|
lib/feedparser/parser.rb
|
12
11
|
lib/feedparser/version.rb
|
@@ -16,5 +15,4 @@ test/feeds/quirksblog.atom.v03
|
|
16
15
|
test/helper.rb
|
17
16
|
test/test_atom.rb
|
18
17
|
test/test_atom_from_file.rb
|
19
|
-
test/test_atom_v03.rb
|
20
18
|
test/test_rss.rb
|
data/README.md
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
feedparser gems - web feed parser and normalizer (RSS 2.0, Atom, etc.)
|
4
4
|
|
5
|
-
* home :: [github.com/
|
6
|
-
* bugs :: [github.com/
|
7
|
-
* gem :: [rubygems.org/gems/
|
8
|
-
* rdoc :: [rubydoc.info/gems/
|
5
|
+
* home :: [github.com/feedreader/feed.parser](https://github.com/feedreader/feed.parser)
|
6
|
+
* bugs :: [github.com/feedreader/feed.parser/issues](https://github.com/feedreader/feed.parser/issues)
|
7
|
+
* gem :: [rubygems.org/gems/feedparser](https://rubygems.org/gems/feedparser)
|
8
|
+
* rdoc :: [rubydoc.info/gems/feedparser](http://rubydoc.info/gems/feedparser)
|
9
9
|
* forum :: [groups.google.com/group/feedreader](http://groups.google.com/group/feedreader)
|
10
10
|
|
11
11
|
|
@@ -69,11 +69,11 @@ end
|
|
69
69
|
|
70
70
|
~~~
|
71
71
|
require 'open-uri'
|
72
|
-
require '
|
72
|
+
require 'feedparser'
|
73
73
|
|
74
74
|
xml = open( 'http://openfootball.github.io/atom.xml' ).read
|
75
75
|
|
76
|
-
feed =
|
76
|
+
feed = FeedParser::Parser.parse( xml )
|
77
77
|
pp feed
|
78
78
|
~~~
|
79
79
|
|
@@ -88,8 +88,21 @@ pp feed
|
|
88
88
|
TBD
|
89
89
|
|
90
90
|
|
91
|
+
|
92
|
+
## Install
|
93
|
+
|
94
|
+
Just install the gem:
|
95
|
+
|
96
|
+
$ gem install feedparser
|
97
|
+
|
98
|
+
|
91
99
|
## License
|
92
100
|
|
93
|
-
The `
|
101
|
+
The `feedparser` scripts are dedicated to the public domain.
|
94
102
|
Use it as you please with no restrictions whatsoever.
|
95
103
|
|
104
|
+
|
105
|
+
## Questions? Comments?
|
106
|
+
|
107
|
+
Send them along to the [Planet Pluto and Friends Forum/Mailing List](http://groups.google.com/group/feedreader).
|
108
|
+
Thanks!
|
data/lib/feedparser.rb
CHANGED
@@ -15,8 +15,6 @@ require 'feedparser/version' # let it always go first
|
|
15
15
|
require 'feedparser/builder/atom'
|
16
16
|
require 'feedparser/builder/rss'
|
17
17
|
|
18
|
-
require 'feedparser/helper/atom_v03'
|
19
|
-
|
20
18
|
require 'feedparser/feed'
|
21
19
|
require 'feedparser/item'
|
22
20
|
require 'feedparser/parser'
|
data/lib/feedparser/parser.rb
CHANGED
@@ -14,20 +14,13 @@ class Parser
|
|
14
14
|
### Note: lets keep/use same API as RSS::Parser for now
|
15
15
|
def initialize( xml )
|
16
16
|
@xml = xml
|
17
|
-
@atomv03helper = AtomV03Helper.new
|
18
17
|
end
|
19
18
|
|
20
19
|
|
21
20
|
def parse
|
22
21
|
logger.debug "using stdlib rss/#{RSS::VERSION}"
|
23
22
|
|
24
|
-
|
25
|
-
if @atomv03helper.match?( @xml )
|
26
|
-
logger.warn "*** atom v0.3 feed; try to patch/upgrade to 1.0(-ish); please use/find atom v1.0 feed"
|
27
|
-
parser = RSS::Parser.new( @atomv03helper.convert( @xml ))
|
28
|
-
else
|
29
|
-
parser = RSS::Parser.new( @xml )
|
30
|
-
end
|
23
|
+
parser = RSS::Parser.new( @xml )
|
31
24
|
|
32
25
|
parser.do_validate = false
|
33
26
|
parser.ignore_unknown_element = true
|
data/lib/feedparser/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -10,7 +10,7 @@ require 'fetcher'
|
|
10
10
|
|
11
11
|
## our own code
|
12
12
|
|
13
|
-
require '
|
13
|
+
require 'feedparser'
|
14
14
|
|
15
15
|
|
16
16
|
LogUtils::Logger.root.level = :debug
|
@@ -18,18 +18,18 @@ LogUtils::Logger.root.level = :debug
|
|
18
18
|
def parse_feed( url )
|
19
19
|
xml = Fetcher.read( url )
|
20
20
|
|
21
|
-
|
21
|
+
FeedParser::Parser.parse( xml )
|
22
22
|
end
|
23
23
|
|
24
24
|
|
25
25
|
|
26
26
|
def read_feed_from_file( name )
|
27
|
-
File.read( "#{
|
27
|
+
File.read( "#{FeedParser.root}/test/feeds/#{name}")
|
28
28
|
end
|
29
29
|
|
30
30
|
def parse_feed_from_file( name )
|
31
31
|
xml = read_feed_from_file( name )
|
32
32
|
|
33
|
-
|
33
|
+
FeedParser::Parser.parse( xml )
|
34
34
|
end
|
35
35
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feedparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -70,7 +70,6 @@ files:
|
|
70
70
|
- lib/feedparser/builder/atom.rb
|
71
71
|
- lib/feedparser/builder/rss.rb
|
72
72
|
- lib/feedparser/feed.rb
|
73
|
-
- lib/feedparser/helper/atom_v03.rb
|
74
73
|
- lib/feedparser/item.rb
|
75
74
|
- lib/feedparser/parser.rb
|
76
75
|
- lib/feedparser/version.rb
|
@@ -80,7 +79,6 @@ files:
|
|
80
79
|
- test/helper.rb
|
81
80
|
- test/test_atom.rb
|
82
81
|
- test/test_atom_from_file.rb
|
83
|
-
- test/test_atom_v03.rb
|
84
82
|
- test/test_rss.rb
|
85
83
|
homepage: https://github.com/feedreader/feed.parser
|
86
84
|
licenses:
|
@@ -109,7 +107,6 @@ signing_key:
|
|
109
107
|
specification_version: 4
|
110
108
|
summary: feedparser - web feed parser and normalizer (RSS 2.0, Atom, etc.)
|
111
109
|
test_files:
|
112
|
-
- test/test_atom_v03.rb
|
113
110
|
- test/test_atom.rb
|
114
111
|
- test/test_atom_from_file.rb
|
115
112
|
- test/test_rss.rb
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
###
|
5
|
-
# hack:
|
6
|
-
## try to patch/convert old obsolete atom v0.3 to v1(-ish)
|
7
|
-
##
|
8
|
-
## in <feed> convert
|
9
|
-
## version="0.3" => removed/dropped! - use ns for version
|
10
|
-
## xmlns="http://purl.org/atom/ns#" => xmlns="http://www.w3.org/2005/Atom"
|
11
|
-
##
|
12
|
-
## <modified>2014-12-31T15:33:00Z</modified> => <updated>
|
13
|
-
## <issued>2014-12-31T13:02:07Z</issued> => <published>
|
14
|
-
##
|
15
|
-
##
|
16
|
-
## more changes:
|
17
|
-
## author url => author uri
|
18
|
-
## generator @url => generator @uri
|
19
|
-
## tagline => subtitle
|
20
|
-
## copyright => rights
|
21
|
-
## <created>2014-12-31T13:02:07Z</created> => removed/dropped!
|
22
|
-
##
|
23
|
-
## todo/fix: fix/convert content @type @mode - why?? why not??
|
24
|
-
##
|
25
|
-
## content @mode => removed/dropped!
|
26
|
-
## @type=text/plain @mode=escaped => @type=text
|
27
|
-
## @type=text/html @mode=escaped => @type=html
|
28
|
-
|
29
|
-
|
30
|
-
## see also
|
31
|
-
## - rakaz.nl/2005/07/moving-from-atom-03-to-10.html
|
32
|
-
|
33
|
-
|
34
|
-
module FeedParser
|
35
|
-
|
36
|
-
class AtomV03Helper
|
37
|
-
|
38
|
-
include LogUtils::Logging
|
39
|
-
|
40
|
-
def match?( xml )
|
41
|
-
## Note: =~ return nil on match; convert to boolean e.g. always return true|false
|
42
|
-
(xml =~ /<feed\s+version="0\.3"/) != nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def convert( xml )
|
46
|
-
xml = xml.sub( /<feed[^>]+>/ ) do |m|
|
47
|
-
## Note: m passed in is just a string w/ the match (NOT a match data object!)
|
48
|
-
## puts "match (#{m.class.name}): "
|
49
|
-
## pp m
|
50
|
-
el = m.sub( /version="0\.3"/, '' )
|
51
|
-
el = el.sub( /xmlns="http:\/\/purl\.org\/atom\/ns#"/, 'xmlns="http://www.w3.org/2005/Atom"' )
|
52
|
-
el
|
53
|
-
end
|
54
|
-
|
55
|
-
xml = xml.gsub( /<modified>/, '<updated>' )
|
56
|
-
xml = xml.gsub( /<\/modified>/, '</updated>' )
|
57
|
-
|
58
|
-
xml = xml.gsub( /<issued>/, '<published>' )
|
59
|
-
xml = xml.gsub( /<\/issued>/, '</published>' )
|
60
|
-
xml
|
61
|
-
end
|
62
|
-
|
63
|
-
end # class AtomV03Helper
|
64
|
-
|
65
|
-
end # module FeedParser
|
66
|
-
|
data/test/test_atom_v03.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
###
|
2
|
-
# to run use
|
3
|
-
# ruby -I ./lib -I ./test test/test_atom_v03.rb
|
4
|
-
# or better
|
5
|
-
# rake test
|
6
|
-
|
7
|
-
require 'helper'
|
8
|
-
|
9
|
-
|
10
|
-
class TestAtomV03 < MiniTest::Test
|
11
|
-
|
12
|
-
def test_match
|
13
|
-
xmlv1 = read_feed_from_file( 'googlegroups.atom' )
|
14
|
-
xmlv03 = read_feed_from_file( 'quirksblog.atom.v03' )
|
15
|
-
|
16
|
-
atomv03helper = FeedUtils::AtomV03Helper.new
|
17
|
-
|
18
|
-
assert_equal false, atomv03helper.match?( xmlv1 )
|
19
|
-
assert_equal true, atomv03helper.match?( xmlv03 )
|
20
|
-
|
21
|
-
xmlv03up = atomv03helper.convert( xmlv03 )
|
22
|
-
assert_equal false, atomv03helper.match?( xmlv03up )
|
23
|
-
|
24
|
-
pp xmlv03up[0..1000]
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_parse
|
28
|
-
feed = parse_feed_from_file( 'quirksblog.atom.v03' )
|
29
|
-
|
30
|
-
pp feed.updated
|
31
|
-
assert_equal '2014-12-31T15:33:00+00:00', feed.updated.to_s
|
32
|
-
|
33
|
-
pp feed.items[0].updated
|
34
|
-
assert_equal '2014-12-31T15:33:00+00:00', feed.items[0].updated.to_s
|
35
|
-
|
36
|
-
pp feed.items[1].updated
|
37
|
-
assert_equal '2014-11-26T12:11:25+00:00', feed.items[1].updated.to_s
|
38
|
-
end
|
39
|
-
|
40
|
-
end # class TestAtomV03
|
41
|
-
|