hackercli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b99813316a49a7f734835aaf0d913f0e7f318fe5
4
+ data.tar.gz: 7ef92b17ffc21396553663a3ec8471f0220ef1a6
5
+ SHA512:
6
+ metadata.gz: 9317754f66a17e8e6158aa0f61adaab78ed833959fd042f362f8964eb20ffb3c86eb4b171685a12657d7bd982c04b977ee099b3f48f779f1c7bbf54566ac70db
7
+ data.tar.gz: cf74fa1d7c328e73bd433f1d4cae0857dab48270368899ebda3f9adf9b389861ac7d35af257472b555958cac2899b2e9cbb8afd38ddf5a500c19dc1d8d399096
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hackercli.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 kepler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,77 @@
1
+ # Hackercli
2
+
3
+ Uses hacker news RSS (bigrss) and reddit news RSS to print titles, article url, comments url, and any other information
4
+ provided. May be used as a filter for other commands.
5
+
6
+ This is a single file and so may be placed anywhere in the path. Also, one may include it in a project
7
+ and get the array of hashes for each article and use as per requirements.
8
+
9
+ This is NOT dependent on any other gem as it uses and parses the simple RSS feed using +String.scan+ only.
10
+
11
+ The feed used for Hacker News is:
12
+
13
+ https://news.ycombinator.com/bigrss
14
+
15
+ The feed used for Reddit News is (replace ruby with any other subreddit):
16
+
17
+ http://www.reddit.com/r/ruby/.rss
18
+
19
+ Please click these links and check if they are working if there is any problem.
20
+
21
+ hackercli.rb --help
22
+
23
+
24
+ ## Installation
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install hackercli
29
+
30
+ ## Usage
31
+
32
+ hackercli.rb --help
33
+
34
+ To view hacker news titles and info.
35
+
36
+ hackercli.rb
37
+
38
+
39
+ To view only titles:
40
+
41
+ hackercli.rb -t
42
+
43
+ To view reddit ruby:
44
+
45
+ hackercli.rb -s ruby
46
+
47
+ Present the URL of some other RSS feed:
48
+
49
+ hackercli.rb -u https://someurl.com/.rss
50
+
51
+ NOTE: this has been tested only with Hackernews bigrss and reddit news' RSS, so I cannot gaurantee
52
+ how it will behave with others. Some tags such as item, title and link are expected to be present.
53
+
54
+
55
+ ## Testing and debugging
56
+
57
+ If you run into errors, or wish to repeatedly test out, you may save an RSS feed and supply the local file name to
58
+ the program.
59
+
60
+ wget https://news.ycombinator.com/bigrss
61
+ hackercli.rb -u bigrss
62
+
63
+ ## See Also:
64
+
65
+ ### hacker-curse
66
+
67
+ This uses nokogiri to parse the actual Hackernews (or reddit) page, and can print on the CLI as well as
68
+ be used as a library for another application. hacker-curse also provides a curses interface for viewing titles
69
+ and comments, and launching the article or comments page in the GUI browser.
70
+
71
+ ## Contributing
72
+
73
+ 1. Fork it ( https://github.com/[my-github-username]/hackercli/fork )
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env ruby
2
+ # ----------------------------------------------------------------------------- #
3
+ # File: bigrss.rb
4
+ # Description: reads Hacker News bigrss feed and prints out
5
+ # Also works with reddit's rss feed
6
+ #
7
+ # This is just a quick dirty printer mainly meant for printing
8
+ # titles and connecting to the page. HN's rss does not provide any info
9
+ # such as points/age etc. Reddit provides a little more but has to be parsed.
10
+ #
11
+ # Currently saves downloaded file as "last.rss" so you may rerun queries on it
12
+ # using the "-u" flag.
13
+ #
14
+ # Author: j kepler http://github.com/mare-imbrium/canis/
15
+ # Date: 2014-07-20 - 11:37
16
+ # License: MIT
17
+ # Last update: 2014-07-21 17:50
18
+ # ----------------------------------------------------------------------------- #
19
+ # bigrss.rb Copyright (C) 2012-2014 j kepler
20
+
21
+ require 'open-uri'
22
+ require 'cgi'
23
+
24
+ class Bigrss
25
+ # mainly options receives a url
26
+ # Also a file name can be sent especially if testing a program and you dont
27
+ # want to hit the site too often.
28
+ def initialize options={}, &block
29
+ @options = options
30
+ #@arg = arg
31
+ #instance_eval &block if block_given?
32
+ end
33
+
34
+ def run
35
+ resp = []
36
+ filename = @options[:url]
37
+ f = open(filename)
38
+ content = f.read
39
+ content.gsub!('&#x2F;',"/")
40
+ content.gsub!('&#x27;',"'")
41
+ content.gsub!('&#x34;','"')
42
+ content = CGI.unescapeHTML(content)
43
+ File.open("last.rss","w") {|ff| ff.write(content) }
44
+ items = content.scan(/<item>(.*?)<\/item>/)
45
+ items.each_with_index do |e,i|
46
+ e = e.first
47
+ h = {}
48
+ title = e.scan(/<title>(.*?)<\/title/).first.first
49
+ h[:title] = title
50
+ url = e.scan(/<link>(.*?)<\/link/).first.first
51
+ h[:url] = url
52
+ comment_url = ""
53
+ # HN has comments links in a tag
54
+ c = e.scan(/<comments>(.*?)<\/comments/).first
55
+ comment_url = c.first if c
56
+ h[:comments_url] = comment_url
57
+ # reddit gives published date
58
+ if e.index("pubDate")
59
+ pubdate = e.scan(/<pubDate>(.*?)<\/pubDate/).first.first
60
+ h[:pubdate] = pubdate
61
+ end
62
+ # reddit rss does not have comments. link comes embedded inside description
63
+ s = extract_part e, "description", h
64
+ if s
65
+ # for reddit
66
+ split_description s, h
67
+ end
68
+ if block_given?
69
+ yield title, url, comment_url
70
+ else
71
+ #resp << [title, url, comment_url]
72
+ resp << h
73
+ end
74
+ #puts " #{title}#{sep}#{url}#{sep}#{comment_url}"
75
+ end
76
+ return resp unless block_given?
77
+ end
78
+ def extract_part e, tag, hash
79
+ if e.index("<#{tag}>")
80
+ str = e.scan(/<#{tag}>(.*?)<\/#{tag}/).first.first
81
+ hash[tag.to_sym] = str
82
+ return str
83
+ end
84
+ return nil
85
+ end
86
+
87
+ # more for the reddit rss which requires the description to be parsed for comments, article link
88
+ def split_description s, h
89
+ str = s.scan(/<a href="(.*?)">(.*?)<\/a>/)
90
+ if str
91
+ str.each do |e|
92
+ if e[1] == "[link]"
93
+ h[:article_url] = e.first
94
+ elsif e[1].index("comment")
95
+ h[:comment_count] = e[1]
96
+ h[:comments_url] = e.first
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ end
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ #if __FILE__ == $0
111
+ if true
112
+ begin
113
+ url = nil
114
+ # http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
115
+ require 'optparse'
116
+ options = {}
117
+ OptionParser.new do |opts|
118
+ opts.banner = "Usage: #{$0} [options]"
119
+
120
+ opts.on("-v", "--[no-]verbose", "Print description also") do |v|
121
+ options[:verbose] = v
122
+ end
123
+ opts.on("-n N", "--limit", Integer, "limit to N stories") do |v|
124
+ options[:number] = v
125
+ end
126
+ opts.on("-t", "print only titles") do |v|
127
+ options[:titles] = true
128
+ end
129
+ opts.on("-d SEP", String,"--delimiter", "Delimit columns with SEP") do |v|
130
+ options[:delimiter] = v
131
+ end
132
+ opts.on("-s SUBREDDIT", String,"--subreddit", "Get articles from subreddit named SUBREDDIT") do |v|
133
+ options[:subreddit] = v
134
+ url = "http://www.reddit.com/r/#{v}/.rss"
135
+ end
136
+ opts.on("-u URL", String,"--url", "Get articles from URL/file") do |v|
137
+ url = v
138
+ end
139
+ end.parse!
140
+
141
+ #p options
142
+ #p ARGV
143
+
144
+ #filename=ARGV[0];
145
+ url ||= "https://news.ycombinator.com/bigrss"
146
+ options[:url] = url
147
+ klass = Bigrss.new options
148
+ arr = klass.run
149
+ titles_only = options[:titles]
150
+ sep = options[:delimiter] || "\t"
151
+ limit = options[:number] || arr.count
152
+ arr.each_with_index do |e, i|
153
+ break if i >= limit
154
+ if titles_only
155
+ puts "#{e[:title]}"
156
+ else
157
+ unless options[:verbose]
158
+ e.delete(:description)
159
+ end
160
+ if i == 0
161
+ s = e.keys.join(sep)
162
+ puts s
163
+ end
164
+ s = e.values.join(sep)
165
+ puts s
166
+ #puts "#{e[:title]}#{sep}#{e[:url]}#{sep}#{e[:comments_url]}"
167
+ end
168
+ end
169
+ #puts " testing block "
170
+ #klass.run do | t,u,c|
171
+ #puts t
172
+ #end
173
+ ensure
174
+ end
175
+ end
176
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hackercli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hackercli"
8
+ spec.version = Hackercli::VERSION
9
+ spec.authors = ["kepler"]
10
+ spec.email = ["githubkepler.50s@gishpuppy.com"]
11
+ spec.summary = %q{uses Hacker News RSS and Reddit RSS to print titles and other info on command line}
12
+ spec.description = %q{uses Hacker News RSS and Reddit RSS to print titles and other info on command line}
13
+ spec.homepage = "https://github.com/mare-imbrium/hackercli"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "hackercli/version"
2
+
3
+ module Hackercli
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Hackercli
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hackercli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kepler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: uses Hacker News RSS and Reddit RSS to print titles and other info on
42
+ command line
43
+ email:
44
+ - githubkepler.50s@gishpuppy.com
45
+ executables:
46
+ - hackercli.rb
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - bin/hackercli.rb
56
+ - hackercli.gemspec
57
+ - lib/hackercli.rb
58
+ - lib/hackercli/version.rb
59
+ homepage: https://github.com/mare-imbrium/hackercli
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: uses Hacker News RSS and Reddit RSS to print titles and other info on command
83
+ line
84
+ test_files: []