This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
2420_3 #286
Open
Apachina
wants to merge
6
commits into
rubizza-camp:master
Choose a base branch
from
Apachina:2420_3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
2420_3 #286
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
BUNDLE_WITHOUT: "development:test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source 'http://rubygems.org' | ||
|
||
gem 'capybara' | ||
gem 'ohm' | ||
gem 'redis' | ||
gem 'selenium-webdriver' | ||
gem 'shotgun' | ||
gem 'sinatra' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
addressable (2.5.2) | ||
public_suffix (>= 2.0.2, < 4.0) | ||
capybara (3.4.1) | ||
addressable | ||
mini_mime (>= 0.1.3) | ||
nokogiri (~> 1.8) | ||
rack (>= 1.6.0) | ||
rack-test (>= 0.6.3) | ||
xpath (~> 3.1) | ||
childprocess (0.9.0) | ||
ffi (~> 1.0, >= 1.0.11) | ||
ffi (1.9.25) | ||
hiredis (0.6.1) | ||
mini_mime (1.0.0) | ||
mini_portile2 (2.3.0) | ||
mustermann (1.0.2) | ||
nest (3.1.1) | ||
redic | ||
nokogiri (1.8.4) | ||
mini_portile2 (~> 2.3.0) | ||
ohm (3.1.1) | ||
nest (~> 3) | ||
redic (~> 1.5.0) | ||
stal | ||
public_suffix (3.0.2) | ||
rack (2.0.5) | ||
rack-protection (2.0.3) | ||
rack | ||
rack-test (1.1.0) | ||
rack (>= 1.0, < 3) | ||
redic (1.5.0) | ||
hiredis | ||
redis (4.0.1) | ||
rubyzip (1.2.1) | ||
selenium-webdriver (3.13.1) | ||
childprocess (~> 0.5) | ||
rubyzip (~> 1.2) | ||
shotgun (0.9.2) | ||
rack (>= 1.0) | ||
sinatra (2.0.3) | ||
mustermann (~> 1.0) | ||
rack (~> 2.0) | ||
rack-protection (= 2.0.3) | ||
tilt (~> 2.0) | ||
stal (0.3.0) | ||
redic (~> 1.5) | ||
tilt (2.0.8) | ||
xpath (3.1.0) | ||
nokogiri (~> 1.8) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
capybara | ||
ohm | ||
redis | ||
selenium-webdriver | ||
shotgun | ||
sinatra | ||
|
||
BUNDLED WITH | ||
1.16.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source 'http://rubygems.org' | ||
|
||
gem 'ohm' | ||
gem 'capybara' | ||
gem 'redis' | ||
gem 'selenium-webdriver' | ||
gem 'shotgun' | ||
gem 'sinatra' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'sinatra/base' | ||
require 'ohm' | ||
|
||
Dir.glob('./{helpers,controllers}/*.rb').each do |file| | ||
require file | ||
end | ||
|
||
map('/') { run ApplicationController } | ||
map('/table') { run TableController } | ||
map('/analysis') { run AnalysisController } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'sinatra/base' | ||
require 'ohm' | ||
|
||
|
||
|
||
Dir.glob('./{helpers,controllers}/*.rb').each { |file| | ||
require file } | ||
|
||
map('/') { run ApplicationController } | ||
map('/table') { run TableController } | ||
map('/analysis') { run AnalysisController } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# class AnalysisController | ||
class AnalysisController < ApplicationController | ||
get '/:id' do | ||
@id = params[:id] | ||
@first_id = Article[@id].comments.first.id | ||
@last_id = Article[@id].comments.last.id | ||
erb :analysis | ||
end | ||
|
||
post '/:id' do | ||
erb :analysis | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# class ApplicationController | ||
class ApplicationController < Sinatra::Base | ||
helpers ApplicationHelper | ||
|
||
configure do | ||
set :views, './views/' | ||
set :root, File.expand_path('..', __dir__) | ||
end | ||
|
||
get '/' do | ||
title 'My App' | ||
erb :table | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'ohm' | ||
require 'redis' | ||
# class TableController | ||
class TableController < ApplicationController | ||
get '/' do | ||
erb :table | ||
end | ||
|
||
post '/' do | ||
scores = [] | ||
article = Article.create(url: params[:new_url]) unless params[:new_url].empty? | ||
comments = Pars.new(params[:new_url]).comments | ||
comments.each do |comment| | ||
score = ManipulationCommentScore.new(Analytics.new(comment).run).run | ||
scores << score | ||
comment_attribute = Comment.create(body: comment, comment_rating: score) | ||
article.comments.push(comment_attribute) | ||
end | ||
article.update article_rating: ManipulationArticleScore.new(scores).run | ||
erb :table | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# module ApplicationHelper | ||
module ApplicationHelper | ||
def title(value = nil) | ||
@title = value if value | ||
@title || 'MyApp' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# class ManipulationCommentScore | ||
class ManipulationCommentScore | ||
attr_reader :score | ||
|
||
def initialize(score) | ||
@score = score | ||
end | ||
|
||
def run | ||
result = score * 100 / 0.5 - 100 if score <= 0.5 | ||
result = (score - 0.5) * 100 / 0.5 if score >= 0.5 | ||
result.round | ||
end | ||
end | ||
# class ManipulationArticleScore | ||
class ManipulationArticleScore | ||
attr_reader :scores | ||
|
||
def initialize(scores) | ||
@scores = scores | ||
end | ||
|
||
def run | ||
scores.sum / scores.size.to_i | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'ohm' | ||
# class Article | ||
class Article < Ohm::Model | ||
list :comments, :Comment | ||
attribute :article_rating | ||
attribute :url | ||
end | ||
# class Comment | ||
class Comment < Ohm::Model | ||
attribute :body | ||
attribute :comment_rating | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'capybara' | ||
|
||
Capybara.register_driver :selenium do |app| | ||
Capybara::Selenium::Driver.new(app, browser: :chrome) | ||
end | ||
# :reek:FeatureEnvy | ||
# rubocop:disable Metrics/LineLength | ||
class Pars | ||
attr_reader :link | ||
|
||
def initialize(link) | ||
@link = link | ||
end | ||
|
||
def comments | ||
session = Capybara::Session.new(:selenium) | ||
session.visit(link) | ||
session.find('a.button-style.button-style_subsidiary.button-style_big.news-form__button.news-form__button_width_full.news-form__button_font-weight_semibold').click | ||
session.find_by_id('comments') | ||
.all('.news-comment__speech.news-comment__speech_base' || '.news-comment__unit') | ||
.first(20) | ||
.map(&:text) | ||
end | ||
end | ||
# rubocop:enable Metrics/LineLength |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'net/https' | ||
require 'uri' | ||
require 'json' | ||
# :reek:FeatureEnvy | ||
# :reek:TooManyStatements | ||
# rubocop:disable Metrics/MethodLength | ||
# rubocop:disable Metrics/AbcSize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/AbcSize. |
||
class Analytics | ||
attr_reader :text | ||
|
||
def initialize(text) | ||
@text = text | ||
end | ||
|
||
def run | ||
access_key = SECRET_KEY.freeze | ||
|
||
uri = 'https://westcentralus.api.cognitive.microsoft.com' | ||
path = '/text/analytics/v2.0/sentiment' | ||
|
||
uri = URI(uri + path) | ||
|
||
documents = { 'documents': [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/Syntax: unexpected token tCOLON |
||
{ 'id' => '1', 'language' => 'ru', 'text' => text } | ||
] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/Syntax: unexpected token tRCURLY |
||
request = Net::HTTP::Post.new(uri) | ||
request['Content-Type'] = 'application/json' | ||
request['Ocp-Apim-Subscription-Key'] = access_key | ||
request.body = documents.to_json | ||
|
||
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| | ||
http.request(request) | ||
end | ||
|
||
information = JSON.pretty_generate(JSON(response.body)) | ||
information = information.gsub(/^\s+|\n|\r|\s+$|\D/, ' ').split | ||
(information[0] + '.' + information[1]).to_f | ||
end | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
# rubocop:enable Metrics/AbcSize |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<CENTER> | ||
<h1>All comments</h1> | ||
<table BORDER CELLPADDING=10 CELLSPACING=0> | ||
<% for id in @first_id..@last_id %> | ||
<tr> | ||
<td><%= Comment[id].body %></td> | ||
<td><%= Comment[id].comment_rating %></td> | ||
</tr> | ||
<%end%> | ||
|
||
<form> | ||
<button> | ||
<a href="/table"> Comeback | ||
</a> | ||
</button> | ||
</form> | ||
</CENTER> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title><%= title%></title> | ||
</head> | ||
<body style = 'background: url(https://images.wallpaperscraft.ru/image/setka_seryy_fon_svetlyy_83492_2048x1152.jpg); background-size: 100% 100%;'> | ||
<%= yield %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<CENTER> | ||
<h1>Добавьте новый URL: </h1> | ||
<form action="/table" method="POST"> | ||
<input type="text" name="new_url" /> | ||
<input type="submit" /> | ||
</form> | ||
<table BORDER CELLPADDING=10 CELLSPACING=0> | ||
<% Article.all.each do |article| %> | ||
<tr> | ||
<td><a href='#'><%= article.url %></a></td> | ||
<td><%= article.article_rating %></td> | ||
<td> | ||
<a href=<%= "/analysis/#{article.id}" %>>Линка</a> | ||
</td> | ||
</tr> | ||
<%end%> | ||
</CENTER> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
<% provide(:title, "Table") %> | ||
<table border="6" cellspacing="0" cellpadding="15" width="90%" height="130"> | ||
<% LINKS.each do |link| %> | ||
<tr> | ||
<td><a href="URL"><%= Ohm.redis.call "GET", link %></a></td> | ||
<td>ахуительная ячейка</td> | ||
</tr> | ||
<%end%> | ||
|
||
|
||
|
||
|
||
<h1>Добавьте новый URL </h1> | ||
|
||
<form action="/table" method="POST"> | ||
|
||
<input type="text" name="new_url" /> | ||
<input type="submit" /> | ||
|
||
</form> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/MethodLength.