dev_to 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/Rakefile +15 -1
- data/bin/console +0 -7
- data/config/environment.rb +2 -4
- data/dev_to.gemspec +2 -0
- data/lib/dev_to/cli.rb +17 -13
- data/lib/dev_to/post.rb +6 -1
- data/lib/dev_to/scraper.rb +28 -17
- data/lib/dev_to/version.rb +1 -1
- data/pkg/dev_to-0.1.4.gem +0 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8827db5153497d828499b3a86e0781c1f5df85300bf608bbd3a6c92c9f7db70e
|
4
|
+
data.tar.gz: 5d3c56fa1e01a2fbcab6442d48af85e734ff626436428fe433900ab4ef672b4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b04d94356ea67e4a368939f29513edae0aa99520b2d08c82789a0725b2c1730ecb799131489fc9bdee855f90a39d3f6f86b852333eda2560a7ef1def7c97fb2
|
7
|
+
data.tar.gz: a3125ee0c1895f90b32ecb384a4fda92c3b9f1e818ba5032f35e41d86b9d2a4027d491357984f470de58389f8daf881fdbc584ffb8b530f6ae09ed94885fdede
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dev_to (0.1.
|
4
|
+
dev_to (0.1.4)
|
5
5
|
colorize (~> 0.8.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -18,6 +18,7 @@ GEM
|
|
18
18
|
coderay (~> 1.1.0)
|
19
19
|
method_source (~> 0.9.0)
|
20
20
|
rake (10.5.0)
|
21
|
+
require_all (1.4.0)
|
21
22
|
rspec (3.7.0)
|
22
23
|
rspec-core (~> 3.7.0)
|
23
24
|
rspec-expectations (~> 3.7.0)
|
@@ -41,6 +42,7 @@ DEPENDENCIES
|
|
41
42
|
nokogiri (~> 1.6, >= 1.6.8)
|
42
43
|
pry (~> 0.11.2)
|
43
44
|
rake (~> 10.0)
|
45
|
+
require_all (~> 1.3, >= 1.3.3)
|
44
46
|
rspec (~> 3.0)
|
45
47
|
|
46
48
|
BUNDLED WITH
|
data/Rakefile
CHANGED
@@ -3,4 +3,18 @@ require "rspec/core/rake_task"
|
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
|
-
task :default => :spec
|
6
|
+
#task :default => :spec
|
7
|
+
|
8
|
+
task :environment do
|
9
|
+
require_relative './config/environment'
|
10
|
+
end
|
11
|
+
|
12
|
+
desc 'load all files'
|
13
|
+
task :reload => :environment do
|
14
|
+
load_all './lib'
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'drop into the Pry console'
|
18
|
+
task :console => :environment do
|
19
|
+
Pry.start
|
20
|
+
end
|
data/bin/console
CHANGED
@@ -3,12 +3,5 @@
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "dev_to"
|
5
5
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
6
|
require "irb"
|
14
7
|
IRB.start(__FILE__)
|
data/config/environment.rb
CHANGED
@@ -2,8 +2,6 @@ require 'pry'
|
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'open-uri'
|
4
4
|
require 'colorize'
|
5
|
+
require 'require_all'
|
5
6
|
|
6
|
-
|
7
|
-
require_relative '../lib/dev_to/cli'
|
8
|
-
require_relative '../lib/dev_to/post'
|
9
|
-
require_relative '../lib/dev_to/scraper'
|
7
|
+
require_all 'lib'
|
data/dev_to.gemspec
CHANGED
@@ -26,5 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
27
|
spec.add_development_dependency "nokogiri", "~> 1.6", ">= 1.6.8"
|
28
28
|
spec.add_development_dependency "pry", "~> 0.11.2"
|
29
|
+
spec.add_development_dependency "require_all", "~> 1.3", ">= 1.3.3"
|
30
|
+
|
29
31
|
spec.add_dependency "colorize", "~> 0.8.1"
|
30
32
|
end
|
data/lib/dev_to/cli.rb
CHANGED
@@ -17,22 +17,22 @@ class DevTo::CLI
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def print_post(
|
20
|
+
def print_post(current_post)
|
21
21
|
puts
|
22
22
|
puts
|
23
|
-
puts "#{
|
24
|
-
puts " ---- #{
|
23
|
+
puts "#{current_post.title}".colorize(:color => :light_white, :background => :red)
|
24
|
+
puts " ---- #{current_post.author} ---- #{current_post.date}"
|
25
25
|
puts
|
26
|
-
puts "#{
|
26
|
+
puts wrap("#{current_post.content}")
|
27
27
|
puts
|
28
|
-
puts " ---- #{
|
29
|
-
puts " ---- #{
|
28
|
+
puts " ---- #{current_post.tags.join(" · ")} \u{1F4AC} #{current_post.comments} \u{2764} #{current_post.likes}"
|
29
|
+
puts " ---- #{current_post.url}"
|
30
30
|
puts
|
31
31
|
end
|
32
32
|
|
33
33
|
def start
|
34
34
|
input = nil
|
35
|
-
|
35
|
+
current_post = nil
|
36
36
|
while input != "exit"
|
37
37
|
puts
|
38
38
|
puts "< Type post NUMBER to read it >"
|
@@ -43,18 +43,22 @@ class DevTo::CLI
|
|
43
43
|
if input == "list"
|
44
44
|
list_posts
|
45
45
|
elsif input.to_i.between?(1, DevTo::Post.all.size)
|
46
|
-
|
47
|
-
DevTo::Scraper.new.make_content(
|
48
|
-
print_post(
|
46
|
+
current_post = DevTo::Post.find(input)
|
47
|
+
current_post.content ? current_post : DevTo::Scraper.new.make_content(current_post)
|
48
|
+
print_post(current_post)
|
49
49
|
puts "< Type OPEN to see it in the browser >"
|
50
|
-
|
50
|
+
current_post
|
51
51
|
elsif input.to_i > DevTo::Post.all.size
|
52
52
|
puts
|
53
53
|
puts " -------- Please select a valid option:"
|
54
|
-
elsif input == "open" &&
|
55
|
-
system("open #{
|
54
|
+
elsif input == "open" && current_post != nil
|
55
|
+
system("open #{current_post.url}")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
puts " -------- See you soon for more DEV Posts"
|
59
59
|
end
|
60
|
+
|
61
|
+
def wrap(text, width=78)
|
62
|
+
text.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
|
63
|
+
end
|
60
64
|
end
|
data/lib/dev_to/post.rb
CHANGED
@@ -3,10 +3,15 @@ class DevTo::Post
|
|
3
3
|
|
4
4
|
@@all = []
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize(attributes_hash)
|
7
|
+
attributes_hash.each {|attribute, value| self.send(("#{attribute}="), value)}
|
7
8
|
self.class.all << self
|
8
9
|
end
|
9
10
|
|
11
|
+
def add_post_attributes(attributes_hash)
|
12
|
+
attributes_hash.each {|attribute, value| self.send(("#{attribute}="), value)}
|
13
|
+
end
|
14
|
+
|
10
15
|
def self.find(id)
|
11
16
|
self.all[id.to_i-1]
|
12
17
|
end
|
data/lib/dev_to/scraper.rb
CHANGED
@@ -4,26 +4,37 @@ class DevTo::Scraper
|
|
4
4
|
Nokogiri::HTML(open("https://dev.to/"))
|
5
5
|
end
|
6
6
|
|
7
|
-
def get_posts
|
8
|
-
self.get_page.css(".articles-list .substories .single-article")
|
9
|
-
end
|
10
|
-
|
11
7
|
def make_posts
|
12
|
-
|
13
|
-
|
14
|
-
post.title = data.search(".content h3 span").remove
|
15
|
-
post.title = data.search(".content h3").text.strip.gsub(/[[:space:]]+/," ")
|
16
|
-
post.author = data.search("h4").text.strip
|
17
|
-
post.tags = data.search(".tags .tag").collect { |tag| tag.text.strip}
|
18
|
-
post.url = "https://dev.to" + data.search("a").last.attr("href")
|
19
|
-
post.comments = data.search(".engagement-count-number").first.text.strip
|
20
|
-
post.likes = data.search(".engagement-count-number").last.text.strip
|
8
|
+
posts.each do |post|
|
9
|
+
DevTo::Post.new(scrape_posts(post))
|
21
10
|
end
|
22
11
|
end
|
23
12
|
|
24
|
-
def make_content(
|
25
|
-
post_page = Nokogiri::HTML(open("#{
|
26
|
-
|
27
|
-
post.date = post_page.search("#main-title .published-at").text.strip
|
13
|
+
def make_content(current_post)
|
14
|
+
post_page = Nokogiri::HTML(open("#{current_post.url}"))
|
15
|
+
current_post.add_post_attributes(scrape_content(post_page))
|
28
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def posts
|
20
|
+
posts ||= get_page.css(".articles-list .substories .single-article")
|
21
|
+
end
|
22
|
+
|
23
|
+
def scrape_posts(post)
|
24
|
+
{
|
25
|
+
:title => post.search(".content h3").text.strip.gsub(/[[:space:]]+/," "),
|
26
|
+
:author => post.search("h4").text.strip,
|
27
|
+
:tags => post.search(".tags .tag").collect { |tag| tag.text.strip},
|
28
|
+
:url => "https://dev.to" + post.search("a").last.attr("href"),
|
29
|
+
:comments => post.search(".engagement-count-number").first.text.strip,
|
30
|
+
:likes => post.search(".engagement-count-number").last.text.strip,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def scrape_content(post_page)
|
35
|
+
{
|
36
|
+
:date => post_page.search("#main-title .published-at").text.strip,
|
37
|
+
:content => post_page.search("body #article-body").text.strip
|
38
|
+
}
|
39
|
+
end
|
29
40
|
end
|
data/lib/dev_to/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PRbsas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,26 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 0.11.2
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: require_all
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.3'
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.3.3
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1.3'
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 1.3.3
|
89
109
|
- !ruby/object:Gem::Dependency
|
90
110
|
name: colorize
|
91
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,6 +145,7 @@ files:
|
|
125
145
|
- lib/dev_to/post.rb
|
126
146
|
- lib/dev_to/scraper.rb
|
127
147
|
- lib/dev_to/version.rb
|
148
|
+
- pkg/dev_to-0.1.4.gem
|
128
149
|
- spec.md
|
129
150
|
- spec/dev_to_spec.rb
|
130
151
|
- spec/spec_helper.rb
|