govfeed 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +57 -0
- data/lib/govfeed.rb +83 -37
- data/lib/govfeed/version.rb +1 -1
- metadata +3 -2
data/README
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
Gem Name: Govfeed
|
2
|
+
Author: Matthew Grigajtis
|
3
|
+
Website: http://www.matthewgrigajtis.com
|
4
|
+
|
5
|
+
This Gem is meant to be a collection of Government, political, and Economic RSS\Atom feeds that are very easy to pull and parse. Since I couldn't find a RSS parsing Gem that worked well under Ruby 1.9.2, I decided to use Curb and Hricot. These two gems are required dependencies.
|
6
|
+
|
7
|
+
I tried to include all RSS\Atom feeds for Canada and the United States, but not all provinces\states have feeds. I hope to add many more in the future.
|
8
|
+
|
9
|
+
Usage is very simple. Include the Gem in whatever project you are using. Get getFeedList function will return the Hash array of feeds that are currently available. The getFeed(:fee_name, # of feeds to display) function will display a simple HTML output of the feed with class names in the Divs so you can add your own styling. The second parameter to the function is optional. If left out, it will display all feeds.
|
10
|
+
|
11
|
+
Here are the feeds currently available:
|
12
|
+
:us_federal United States Federal Government
|
13
|
+
:us_al Alabama
|
14
|
+
:us_az Arizona
|
15
|
+
:us_ca California
|
16
|
+
:us_de Delaware
|
17
|
+
:us_ga Georgia
|
18
|
+
:us_hi Hawaii
|
19
|
+
:us_il Illinois
|
20
|
+
:us_in Indiana
|
21
|
+
:us_ks Kansas
|
22
|
+
:us_ky Kentucky
|
23
|
+
:us_la Louisiana
|
24
|
+
:us_me Maine
|
25
|
+
:us_md Maryland
|
26
|
+
:us_ma Massachusetts
|
27
|
+
:us_mi Michigan
|
28
|
+
:us_mo Missouri
|
29
|
+
:us_nj New Jersey
|
30
|
+
:us_nm New Mexico
|
31
|
+
:us_ny New York
|
32
|
+
:us_nc North Carolina
|
33
|
+
:us_nd North Dakota
|
34
|
+
:us_oh Ohio
|
35
|
+
:us_ok Oklahoma
|
36
|
+
:us_pa Pennsylvania
|
37
|
+
:us_ri Rhode Island
|
38
|
+
:us_sd South Dakota
|
39
|
+
:us_tn Tennessee
|
40
|
+
:us_tx Texas
|
41
|
+
:us_va Virginia
|
42
|
+
:us_vt Vermont
|
43
|
+
:us_wa Washington
|
44
|
+
:us_wv West Virginia
|
45
|
+
:us_wi Wisconsin
|
46
|
+
:cato The Cato Institute Think Tank
|
47
|
+
:heritage The Heritage Foundation Think Tank
|
48
|
+
:mises The Ludwig von Mises School of Economic Thought
|
49
|
+
:ca_federal The Canadian Federal Government
|
50
|
+
:ca_ab Alberta
|
51
|
+
:ca_bc British Columbia
|
52
|
+
:ca_mn Manitoba
|
53
|
+
:ca_nb New Brunswick
|
54
|
+
:ca_ns Novia Scotia
|
55
|
+
:ca_on Ontario
|
56
|
+
:ca_pe Prince Edward Island
|
57
|
+
:ca_sk Seskatchawan
|
data/lib/govfeed.rb
CHANGED
@@ -64,55 +64,101 @@ module Govfeed
|
|
64
64
|
}
|
65
65
|
end
|
66
66
|
|
67
|
+
def self.getItemTitle(item)
|
68
|
+
|
69
|
+
title = String.new
|
70
|
+
|
71
|
+
if (item/"title") != nil
|
72
|
+
title = "<a href=\"" + (item/"link").inner_text + "\"><h2 class=\"govfeedHeading\">" + (item/"title").inner_text + "</h2></a>\n"
|
73
|
+
end
|
74
|
+
|
75
|
+
title
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.getItemPubDate(item)
|
80
|
+
|
81
|
+
pubDate = String.new
|
82
|
+
|
83
|
+
if (item/"pubDate") != nil
|
84
|
+
pubDate = "<div class=\"govfeedPubDate\">" + (item/"pubDate").inner_text + "</div>\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
pubDate
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.getItemDescription(item)
|
92
|
+
|
93
|
+
description = String.new
|
94
|
+
|
95
|
+
if (item/"description") != nil
|
96
|
+
description = "<div class=\"govfeedDescription\">" + self.truncate_words((item/"description").inner_text, 40) + "</div>\n"
|
97
|
+
end
|
98
|
+
|
99
|
+
description
|
100
|
+
|
101
|
+
end
|
67
102
|
|
68
103
|
def self.getFeed(feed, numberOfStories = 0)
|
104
|
+
begin
|
105
|
+
counter = 0
|
106
|
+
|
107
|
+
# This hash contains the Feed URLs
|
108
|
+
# The format goes Federal feeds, State\Province feeds, Think Tank\Institution feeds
|
109
|
+
# Some states\provinces\territories do not yet have RSS feeds or feeds that work (Idaho).
|
110
|
+
# They will be added to this hash when they are created or fixed.
|
111
|
+
feed_url = self.getFeedList
|
69
112
|
|
70
|
-
|
71
|
-
|
72
|
-
# Some states\provinces\territories do not yet have RSS feeds or feeds that work (Idaho).
|
73
|
-
# They will be added to this hash when they are created or fixed.
|
74
|
-
feed_url = self.getFeedList
|
75
|
-
|
76
|
-
# Curb-Fu will be fetching the feed.
|
77
|
-
feed = CurbFu.get(feed_url[feed])
|
113
|
+
# Curb-Fu will be fetching the feed.
|
114
|
+
feed = CurbFu.get(feed_url[feed])
|
78
115
|
|
79
|
-
|
80
|
-
|
116
|
+
# the hpricot gem will be used to parse it as we build the HTML
|
117
|
+
doc = Hpricot.XML(feed.body.to_s)
|
81
118
|
|
82
|
-
|
83
|
-
|
119
|
+
# RSS feed title
|
120
|
+
rss = "<h1 class=\"govfeedTitle\">" + (doc/"title")[0].inner_text + "</h1>\n"
|
84
121
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
122
|
+
# Make sure that the feed description exists before attempting to parse it
|
123
|
+
if (((doc/"description")[0] != nil) || ((doc/"description")[0] != ""))
|
124
|
+
rss += "<div class=\"govfeedDescription\">" + (doc/"description")[0].inner_text + "</div>\n"
|
125
|
+
end
|
89
126
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
127
|
+
# Make sure that the feed image exists before attempting to parse it
|
128
|
+
if (doc/"image")[0] != nil
|
129
|
+
rss += "<div class=\"govfeedImage\"><img src=\"" + (doc/"image"/"url")[0].inner_text + "\" alt=\"" + (doc/"image"/"title")[0].inner_text + "\" /></div>\n"
|
130
|
+
end
|
94
131
|
|
95
|
-
|
96
|
-
|
97
|
-
if numberOfStories == 0
|
98
|
-
(doc/"item").each do |item|
|
99
|
-
rss += "<a href=\"" + (item/"link").inner_text + "\"><h2 class=\"govfeedHeading\">" + (item/"title").inner_text + "</h2></a>\n"
|
100
|
-
rss += "<div class=\"govfeedDiv\">" + (item/"pubDate").inner_text + "<br />" + self.truncate_words((item/"description").inner_text, 40) + "</div>\n"
|
101
|
-
end
|
102
|
-
else
|
103
|
-
counter = 0
|
132
|
+
# individual RSS feed items
|
133
|
+
# If the number of stories parameter was not passed in, fetch all
|
104
134
|
(doc/"item").each do |item|
|
105
|
-
|
106
|
-
rss +=
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
135
|
+
|
136
|
+
rss += self.getItemTitle(item)
|
137
|
+
|
138
|
+
rss += self.getItemPubDate(item)
|
139
|
+
|
140
|
+
rss += self.getItemDescription(item)
|
141
|
+
|
142
|
+
# If the number of stories is not equal to 0, that means it was limited
|
143
|
+
if numberOfStories != 0
|
144
|
+
|
145
|
+
counter = counter + 1
|
146
|
+
|
147
|
+
if counter == numberOfStories
|
148
|
+
break
|
149
|
+
end
|
150
|
+
|
111
151
|
end
|
152
|
+
|
112
153
|
end
|
113
|
-
end
|
114
154
|
|
115
|
-
|
155
|
+
rss
|
156
|
+
|
157
|
+
rescue
|
158
|
+
|
159
|
+
"Could not parse RSS feed."
|
160
|
+
|
161
|
+
end
|
116
162
|
|
117
163
|
end
|
118
164
|
|
data/lib/govfeed/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: govfeed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Matthew Grigajtis
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-10-
|
13
|
+
date: 2011-10-22 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -26,6 +26,7 @@ extra_rdoc_files: []
|
|
26
26
|
files:
|
27
27
|
- .gitignore
|
28
28
|
- Gemfile
|
29
|
+
- README
|
29
30
|
- Rakefile
|
30
31
|
- govfeed.gemspec
|
31
32
|
- lib/govfeed.rb
|