cinch-news 1.0.2 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 66bb861417cb43f4104ca0063d91267a4898cb2c
4
- data.tar.gz: 141ff2d85f4c1665794d9c9644a39cd2001e4c1e
3
+ metadata.gz: 1f5edc6bdacb752d09cda39b6d59713d3d798017
4
+ data.tar.gz: 832629ce346ead1d0dfbefd13737b28b574c5e91
5
5
  SHA512:
6
- metadata.gz: 21751bdbc3838edea21510528732446d5da105336ef9fd8a19987818697818ccd40b4921a444cd7650e60e459b6618bd6b3e8813ebaeb17107b58b87b6f09953
7
- data.tar.gz: 991040fbe9be311764ad1515d60f7e8e9be59480deb62e937f97f673515b626e1e0e2c9bc69a8dc6725b09e850d23990c47cbc8ab1ff95eae122bbefde1bea57
6
+ metadata.gz: cc5234a147ec0e7aec07476d2adc32d121530ed2f6ae156453f3ffcaa481125034030bd17f5656a6b1c3084b8d5024d51b270a1e1ad4921ee4e9a3adbe595df5
7
+ data.tar.gz: f72368f9a9436301f398879d898af805e43f5b68b2f7d7a23b272fd95abc157c9147316401a5ddb93ac4730a84d5423abecaee879287624072cc580ddf75f553
@@ -0,0 +1,168 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+ require 'ostruct'
4
+ require 'cinch/toolbox'
5
+
6
+ module Cinch
7
+ module Helpers
8
+
9
+ def categories
10
+ c_data = JSON.parse(open("http://api.feedzilla.com/v1/categories.json").read)
11
+ c_list = []
12
+
13
+ for i in c_data
14
+ c_title = i['english_category_name']
15
+ c_id = i['category_id']
16
+
17
+ c_list.push("%s [ %s ]" % [c_title, c_id])
18
+ end
19
+ return c_list
20
+ end
21
+
22
+ def sub_categories(id)
23
+ sc_data = JSON.parse(open("http://api.feedzilla.com/v1/categories/#{id}/subcategories.json").read)
24
+ sc_list = []
25
+
26
+ for i in sc_data
27
+ sc_title = i['display_subcategory_name']
28
+ sc_id = i['subcategory_id']
29
+
30
+ sc_list.push("%s [ %s ]" % [sc_title, sc_id])
31
+ end
32
+ return sc_list
33
+ end
34
+
35
+ def execute_c_search(id, terms)
36
+ search_c_data = JSON.parse(open("http://api.feedzilla.com/v1/categories/#{id}/articles/search.json?q=#{terms}&count=4").read)
37
+ s_c_data = search_c_data['articles']
38
+ search_c_list = []
39
+
40
+ for i in s_c_data
41
+ article_source = i['source']
42
+ article_title = i['title']
43
+ article_summary = i['summary']
44
+ article_url = i['url']
45
+
46
+ url = article_url
47
+ url = Cinch::Toolbox.shorten(url)
48
+
49
+ url = /"shorturl": "(.+)"/.match(url)[1]
50
+
51
+ summary = article_summary[0..200]
52
+
53
+ summary_s = summary.gsub! /\n/, ' '
54
+
55
+ search_c_list.push("%s | Title \"%s\" | Summary: %s [ %s ]" % [article_source, article_title, summary, url])
56
+ end
57
+ return search_c_list
58
+ end
59
+
60
+ def execute_sc_search(id, sc_id, terms)
61
+ search_sc_data = JSON.parse(open("http://api.feedzilla.com/v1/categories/#{id}/subcategories/#{sc_id}/articles/search.json?q=#{terms}&count=4").read)
62
+ s_sc_data = search_sc_data['articles']
63
+ search_sc_list = []
64
+
65
+ for i in s_sc_data
66
+ article_source = i['source']
67
+ article_title = i['title']
68
+ article_summary = i['summary']
69
+ article_url = i['url']
70
+
71
+ url = article_url
72
+ url = Cinch::Toolbox.shorten(url)
73
+
74
+ url = /"shorturl": "(.+)"/.match(url)[1]
75
+
76
+ summary = article_summary[0..200]
77
+
78
+ summary_s = summary.gsub! /\n/, ' '
79
+
80
+ search_sc_list.push("%s | Title \"%s\" | Summary: %s [ %s ]" % [article_source, article_title, summary_s, url])
81
+ end
82
+ return search_sc_list
83
+ end
84
+
85
+ def fetch_news
86
+ news_data = JSON.parse(open("http://api.feedzilla.com/v1/categories/26/articles.json?&count=4").read)
87
+ news_articles = news_data['articles']
88
+ news_list = []
89
+
90
+ for i in news_articles
91
+ article_source = i['source']
92
+ article_title = i['title']
93
+ article_summary = i['summary']
94
+ article_url = i['url']
95
+
96
+ puts article_url
97
+
98
+ url = article_url
99
+ url = Cinch::Toolbox.shorten(url)
100
+
101
+ url = /"shorturl": "(.+)"/.match(url)[1]
102
+
103
+ puts url.class
104
+
105
+ summary = article_summary[0..200]
106
+
107
+ summary_s = summary.gsub! /\n/, ' '
108
+
109
+ news_list.push("%s | Title \"%s\" | Summary: %s [ #{url} ]" % [article_source, article_title, summary_s])
110
+ end
111
+ return news_list
112
+ end
113
+
114
+ def c_top_news(id)
115
+ c_news_data = JSON.parse(open("http://api.feedzilla.com/v1/categories/#{id}/articles.json?&count=4").read)
116
+ c_news_articles = c_news_data['articles']
117
+ c_news_list = []
118
+
119
+ for i in c_news_articles
120
+ article_source = i['source']
121
+ article_title = i['title']
122
+ article_summary = i['summary']
123
+ article_url = i['url']
124
+
125
+
126
+ url = article_url
127
+ url = Cinch::Toolbox.shorten(url)
128
+
129
+ url = /"shorturl": "(.+)"/.match(url)[1]
130
+
131
+ summary = article_summary[0..200]
132
+
133
+ summary_s = summary.gsub! /\n/, ' '
134
+
135
+ c_news_list.push("%s | Title \"%s\" | Summary: %s [ #{url} ]" % [article_source, article_title, summary_s])
136
+ end
137
+ return c_news_list
138
+ end
139
+
140
+ def sc_top_news(id, sc_id)
141
+ sc_news_data = JSON.parse(open("http://api.feedzilla.com/v1/categories/#{id}/subcategories/#{sc_id}/articles.json?&count=4").read)
142
+ sc_news_articles = sc_news_data['articles']
143
+ sc_news_list = []
144
+
145
+ for i in sc_news_articles
146
+ article_source = i['source']
147
+ article_title = i['title']
148
+ article_summary = i['summary']
149
+ article_url = i['url']
150
+
151
+
152
+ url = article_url
153
+ url = Cinch::Toolbox.shorten(url)
154
+
155
+ url = /"shorturl": "(.+)"/.match(url)[1]
156
+
157
+ summary = article_summary[0..200]
158
+
159
+ summary_s = summary.gsub! /\n/, ' '
160
+
161
+ sc_news_list.push("%s | Title \"%s\" | Summary: %s [ #{url} ]" % [article_source, article_title, summary_s])
162
+ end
163
+ return sc_news_list
164
+ end
165
+
166
+ end
167
+ end
168
+
@@ -1,89 +1,97 @@
1
- # @author Richard Banks <namaste@rawrnet.net>
2
-
3
- # Feel free to join us in #Lobby on irc://rawr.sinsira.net where you can test this gem and get help!
4
-
5
- require 'cinch'
6
- require 'ostruct'
7
- require 'open-uri'
8
- require 'json'
9
- require 'cgi'
10
- require 'cinch/toolbox'
11
-
12
- module Cinch
13
- module Plugins
14
- class News
15
- include Cinch::Plugin
16
-
17
- match /news$/, method: :top_news
18
-
19
- match /news (tech|money|travel|sports|life|weather|nation|offbeat|washington|world|religion|opinion|health|nfl|mlb|nba|nhl|collegefootball|collegebasketball|highschool|motorsports|golf|soccer|olympics|horseracing|people|books|music|movies)/, method: :category_news
20
-
21
- match /s-news (.+)/, method: :search_news
22
-
23
- def top_news(m)
24
- data = fetch_news(m)
25
- return m.reply "There was a problem fetching the news." if data.empty?
26
- output_news(m, data)
27
- end
28
-
29
- def category_news(m, category)
30
- data = fetch_category(m, category)
31
- return m.reply "There was a problem fetching the news for #{category}." if data.empty?
32
- output_news(m, data)
33
- end
34
-
35
- def search_news(m, terms)
36
- data = fetch_search(m, terms)
37
- return m.reply "No news results found for #{terms}." if data == false
38
- output_news(m, data)
39
- end
40
-
41
- def fetch_news(m)
42
- key = config[:key]
43
- data = JSON.parse(open("http://api.usatoday.com/open/articles/topnews?api_key=#{key}&encoding=json&count=3").read)
44
- stories = data['stories']
45
- output = []
46
- stories.each{|i|
47
- url = i['link']
48
- url.gsub! /apidata./, ''
49
- url = Cinch::Toolbox.shorten(url)
50
- output.push("News: | \"%s\" | Description: %s [ #{url} ]" % [i['title'], i['description']])}
51
- return output
52
- end
53
-
54
- def fetch_category(m, category)
55
- key = config[:key]
56
- data = JSON.parse(open("http://api.usatoday.com/open/articles/topnews/#{category}?api_key=#{key}&encoding=json&count=3").read)
57
- stories = data['stories']
58
- output = []
59
- stories.each{|i|
60
- url = i['link']
61
- url.gsub! /apidata./, ''
62
- url = Cinch::Toolbox.shorten(url)
63
- output.push("News: | \"%s\" | Description: %s [ #{url} ]" % [i['title'], i['description']])}
64
- return output
65
- end
66
-
67
- def fetch_search(m, terms)
68
- key = config[:key]
69
- search_uri = URI.encode("http://api.usatoday.com/open/articles?tag=#{terms}&count=3&api_key=#{key}&encoding=json")
70
- data = JSON.parse(open("#{search_uri}").read)
71
- stories = data['stories']
72
- output = []
73
- stories.each{|i|
74
- url = i['link']
75
- url.gsub! /apidata./, ''
76
- url = Cinch::Toolbox.shorten(url)
77
- output.push("News: | \"%s\" | Description: %s [ #{url} ]" % [i['title'], i['description']])}
78
- return output
79
- rescue JSON::ParserError
80
- return false
81
- end
82
-
83
- def output_news(m, data)
84
- return if data == false
85
- data[0..2].each{|i| m.reply i}
86
- end
87
- end
88
- end
89
- end
1
+ # @author Richard Banks <namaste@rawrnet.net>
2
+
3
+ # Feel free to join us in #Lobby on irc://rawr.sinsira.net where you can test this gem and get help!
4
+
5
+ require 'cinch'
6
+ require 'ostruct'
7
+ require 'open-uri'
8
+ require 'json'
9
+ require 'cgi'
10
+ require 'cinch/toolbox'
11
+ require_relative "helpers/category_helper.rb"
12
+
13
+ module Cinch
14
+ module Plugins
15
+ class News
16
+ include Cinch::Plugin
17
+
18
+ set :plugin_name, 'news'
19
+ set :help, <<-USAGE.gsub(/^ {6}/, '')
20
+ This plugin is a comprehensive news aggregator and contacts several sources for articles.
21
+ Enable/Disable Usage:
22
+ * !n-categories: This command returns all the categories that you can choose from in a PM.
23
+ * !n-subcategories <category ID>: This command returns all the subcategories of the specified category and their useable ID.
24
+ * !news: This command retrieves the top three articles from the Top Stories subcategory of the Top News category.
25
+ * !news <category ID>: This command retrieves the top three articles from the specified category.
26
+ * !news <category ID> <subcategory ID>: This command retrieves the top three articles from the specified subcategory of the specified category.
27
+ * !s-category <category id> <query>: This command searches the specified category for your query.
28
+ USAGE
29
+
30
+ match /n-categories/, method: :list_categories
31
+
32
+ match /n-subcategories (.+)/, method: :list_subs
33
+
34
+ match /news$/, method: :top_news
35
+
36
+ match /news (.+)$/, method: :c_topnews
37
+
38
+ match /news (.+?) (.+)/, method: :sc_topnews
39
+
40
+ match /s-category (.+?) (.+)/, method: :search_category
41
+
42
+ match /s-subcategory (.+?) (.+?) (.+)/, method: :search_subcategory
43
+
44
+ def list_categories(m)
45
+ cat_list = categories
46
+ ca_list = cat_list.join(", ")
47
+ m.user.notice "#{ca_list}"
48
+ end
49
+
50
+ def list_subs(m, c_id)
51
+ sc_list = sub_categories(c_id)
52
+ s_list = sc_list.join(", ")
53
+ m.user.notice "#{s_list}"
54
+ end
55
+
56
+
57
+ def search_category(m, id, terms)
58
+ terms.gsub! /\s/, '+'
59
+ search_list = execute_c_search(id, terms)
60
+ search_list[0..2].each{|i| m.reply i}
61
+ rescue OpenURI::HTTPError
62
+ m.reply "Error: #{$!}"
63
+ end
64
+
65
+ def search_subcategory(m, id, sc_id, terms)
66
+ terms.gsub! /\s/, '+'
67
+ sc_search_list = execute_sc_search(id, sc_id, terms)
68
+ sc_search_list[0..2].each{|i| m.reply i}
69
+ rescue OpenURI::HTTPError
70
+ m.reply "Error #{$!}"
71
+ end
72
+
73
+ def top_news(m)
74
+ news = fetch_news
75
+ news[0..2].each{|i| m.reply i}
76
+ rescue OpenURI::HTTPError
77
+ m.reply "Error #{$!}"
78
+ end
79
+
80
+ def c_topnews(m, id)
81
+ c_news = c_top_news(id)
82
+ c_news[0..2].each{|i| m.reply i}
83
+ rescue OpenURI::HTTPError
84
+ m.reply "Error #{$!}"
85
+ end
86
+
87
+ def sc_topnews(m, id, sc_id)
88
+ sc_news = sc_top_news(id, sc_id)
89
+ sc_news[0..2].each{|i| m.reply i}
90
+ rescue OpenURI::HTTPError
91
+ m.reply "Error #{$!}"
92
+ end
93
+
94
+
95
+ end
96
+ end
97
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-news
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Banks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-12 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cinch
@@ -38,15 +38,16 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.1.2
41
- description: ! 'A news gem/plugin for the Cinch IRC bot framework that uses a USA
42
- Today API. You can visit irc://rawr.sinsira.net #Lobby to get help, report issues
43
- , test the gem, or just chat.'
41
+ description: ! 'A news gem/plugin for the Cinch IRC bot framework that uses a FeedZilla
42
+ API. You can visit irc://rawr.sinsira.net #Lobby to get help, report issues , test
43
+ the gem, or just chat.'
44
44
  email:
45
45
  - namaste@rawrnet.net
46
46
  executables: []
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
+ - lib/cinch/plugins/helpers/category_helper.rb
50
51
  - lib/cinch/plugins/news.rb
51
52
  homepage: https://github.com/RawrNet/cinch-news
52
53
  licenses: