Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

2345 - 3 #292

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 2345/3/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source 'https://rubygems.org'

gem 'reek'
gem 'rubocop', '~> 0.54.0'

gem 'sinatra', '~> 1.4', '>= 1.4.7'
gem 'redis', '~> 3.3', '>= 3.3.1'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundler/OrderedGems: Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem redis should appear before sinatra.

gem 'ohm', '~> 3.1', '>= 3.1.1'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundler/OrderedGems: Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem ohm should appear before redis.

gem 'mechanize', '~> 2.7', '>= 2.7.6' # https://rubygems.org/gems/mechanize

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundler/OrderedGems: Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem mechanize should appear before ohm.

# gem 'capybara', '~> 3.4', '>= 3.4.2' # https://rubygems.org/gems/capybara
gem 'shotgun', '~> 0.9.2'
107 changes: 107 additions & 0 deletions 2345/3/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
codeclimate-engine-rb (0.4.1)
virtus (~> 1.0)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
connection_pool (2.2.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
equalizer (0.0.11)
hiredis (0.6.1)
http-cookie (1.0.3)
domain_name (~> 0.5)
ice_nine (0.11.2)
kwalify (0.7.2)
mechanize (2.7.6)
domain_name (~> 0.5, >= 0.5.1)
http-cookie (~> 1.0)
mime-types (>= 1.17.2)
net-http-digest_auth (~> 1.1, >= 1.1.1)
net-http-persistent (>= 2.5.2)
nokogiri (~> 1.6)
ntlm-http (~> 0.1, >= 0.1.1)
webrobots (>= 0.0.9, < 0.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.3.0)
nest (3.1.1)
redic
net-http-digest_auth (1.4.1)
net-http-persistent (3.0.0)
connection_pool (~> 2.2)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
ntlm-http (0.1.1)
ohm (3.1.1)
nest (~> 3)
redic (~> 1.5.0)
stal
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
powerpack (0.1.2)
rack (1.6.10)
rack-protection (1.5.5)
rack
rainbow (3.0.0)
redic (1.5.0)
hiredis
redis (3.3.5)
reek (5.0.2)
codeclimate-engine-rb (~> 0.4.0)
kwalify (~> 0.7.0)
parser (>= 2.5.0.0, < 2.6, != 2.5.1.1)
rainbow (>= 2.0, < 4.0)
rubocop (0.54.0)
parallel (~> 1.10)
parser (>= 2.5)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
shotgun (0.9.2)
rack (>= 1.0)
sinatra (1.4.8)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
stal (0.3.0)
redic (~> 1.5)
thread_safe (0.3.6)
tilt (2.0.8)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.4.0)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
webrobots (0.1.2)

PLATFORMS
ruby

DEPENDENCIES
mechanize (~> 2.7, >= 2.7.6)
ohm (~> 3.1, >= 3.1.1)
redis (~> 3.3, >= 3.3.1)
reek
rubocop (~> 0.54.0)
shotgun (~> 0.9.2)
sinatra (~> 1.4, >= 1.4.7)

BUNDLED WITH
1.16.1
26 changes: 26 additions & 0 deletions 2345/3/mechanize_onliner_0.0.1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'mechanize'

agent = Mechanize.new
page = agent.get('https://people.onliner.by/2018/07/23/vodol')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UselessAssignment: Useless assignment to variable - page.


# reviews = review_links.map do |link|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/CommentIndentation: Incorrect indentation detected (column 0 instead of 2).

# review = page.click
review_meta = review.search('#main .review-meta .info')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

artist = review_meta.search('h1')[0].text

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

album = review_meta.search('h2')[0].text

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

label, year = review_meta.search('h3')[0].text.split(';').map(&:strip)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

reviewer = review_meta.search('h4 address')[0].text

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

review_date = Date.parse(review_meta.search('.pub-date')[0].text)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

score = review_meta.search('.score').text.to_f

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.
Lint/Void: Literal {

artist: artist,
album: album,
label: label,
year: year,
reviewer: reviewer,
review_date: review_date,
score: score
}
# end

puts JSON.pretty_generate(reviews)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/TrailingBlankLines: Final newline missing.

56 changes: 56 additions & 0 deletions 2345/3/onliner_0.0.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'mechanize'

class ArticleParser
include CommentHelper

def initialize(link = 'https://tech.onliner.by/2018/07/24/duglas-censor-martin')
@agent = Mechanize.new
@article_link = link
end

def title
@agent.get(@article_link).search('.news-header__title').text.strip
end

def comments
data['comments'].reverse.map do |comment|
{ author: CommentHelper.author(comment),
text: CommentHelper.text(comment),
votes: CommentHelper.votes(comment) }
end
end

private

def data
JSON.parse(@agent.get(comment_link).body)
end

def comment_link
"https://comments.api.onliner.by/news/#{section}.post/#{article_id}/comments?limit=9999"
end

def section
@article_link[%r{https://(\w+)}, 1]
end

def article_id
@agent.get(@article_link).search('.news_view_count').attr('news_id').value
end
end

module CommentHelper
def self.votes(options)
options['marks'].values.reduce(:+)
end

def self.author(options)
options['author']['name']
end

def self.text(options)
options['text']
end
end