From 7b7a10b30754f22f6dac91f394ce1cd4823e7558 Mon Sep 17 00:00:00 2001 From: Almix047 Date: Fri, 27 Jul 2018 18:47:55 +0000 Subject: [PATCH 1/3] Add homework 2345 for task 3 --- 2345/3/Gemfile | 11 +++ 2345/3/Gemfile.lock | 107 ++++++++++++++++++++++++++++++ 2345/3/mechanize_onliner_0.0.1.rb | 26 ++++++++ 2345/3/onliner_0.0.2 | 56 ++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100755 2345/3/Gemfile create mode 100644 2345/3/Gemfile.lock create mode 100644 2345/3/mechanize_onliner_0.0.1.rb create mode 100644 2345/3/onliner_0.0.2 diff --git a/2345/3/Gemfile b/2345/3/Gemfile new file mode 100755 index 000000000..553533d96 --- /dev/null +++ b/2345/3/Gemfile @@ -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' +gem 'ohm', '~> 3.1', '>= 3.1.1' +gem 'mechanize', '~> 2.7', '>= 2.7.6' # https://rubygems.org/gems/mechanize +# gem 'capybara', '~> 3.4', '>= 3.4.2' # https://rubygems.org/gems/capybara +gem 'shotgun', '~> 0.9.2' diff --git a/2345/3/Gemfile.lock b/2345/3/Gemfile.lock new file mode 100644 index 000000000..231c944a4 --- /dev/null +++ b/2345/3/Gemfile.lock @@ -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 diff --git a/2345/3/mechanize_onliner_0.0.1.rb b/2345/3/mechanize_onliner_0.0.1.rb new file mode 100644 index 000000000..7ad0a881c --- /dev/null +++ b/2345/3/mechanize_onliner_0.0.1.rb @@ -0,0 +1,26 @@ +require 'mechanize' + +agent = Mechanize.new +page = agent.get('https://people.onliner.by/2018/07/23/vodol') + +# reviews = review_links.map do |link| + # review = page.click + review_meta = review.search('#main .review-meta .info') + artist = review_meta.search('h1')[0].text + album = review_meta.search('h2')[0].text + label, year = review_meta.search('h3')[0].text.split(';').map(&:strip) + reviewer = review_meta.search('h4 address')[0].text + review_date = Date.parse(review_meta.search('.pub-date')[0].text) + score = review_meta.search('.score').text.to_f + { + artist: artist, + album: album, + label: label, + year: year, + reviewer: reviewer, + review_date: review_date, + score: score + } +# end + +puts JSON.pretty_generate(reviews) \ No newline at end of file diff --git a/2345/3/onliner_0.0.2 b/2345/3/onliner_0.0.2 new file mode 100644 index 000000000..051940cef --- /dev/null +++ b/2345/3/onliner_0.0.2 @@ -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 + + From c62140ef287f2813dce624424c94e8d9174d2e88 Mon Sep 17 00:00:00 2001 From: Almix047 Date: Wed, 1 Aug 2018 00:01:24 +0000 Subject: [PATCH 2/3] Correcting errors and adding the rest of the files --- 2345/3/.ruby-gemset | 1 + 2345/3/.ruby-version | 1 + 2345/3/Gemfile | 18 ++++---- 2345/3/Gemfile.lock | 8 +++- 2345/3/config.ru | 6 +++ 2345/3/controllers/application_controller.rb | 12 +++++ 2345/3/controllers/articles_controller.rb | 39 ++++++++++++++++ 2345/3/mechanize_onliner_0.0.1.rb | 26 ----------- 2345/3/models/article.rb | 7 +++ 2345/3/models/article_creater.rb | 28 ++++++++++++ .../article_parser.rb} | 26 ++--------- 2345/3/models/comment.rb | 6 +++ 2345/3/models/comment_parser.rb | 13 ++++++ 2345/3/models/comments_rating.rb | 23 ++++++++++ 2345/3/models/create_comments.rb | 15 +++++++ 2345/3/models/pass | 1 + 2345/3/models/rating_counter.rb | 45 +++++++++++++++++++ 2345/3/views/articles/create.erb | 9 ++++ 2345/3/views/articles/edit.erb | 11 +++++ 2345/3/views/articles/index.erb | 29 ++++++++++++ 2345/3/views/articles/show.erb | 28 ++++++++++++ 2345/3/views/not_found.erb | 12 +++++ 22 files changed, 307 insertions(+), 57 deletions(-) create mode 100755 2345/3/.ruby-gemset create mode 100755 2345/3/.ruby-version create mode 100644 2345/3/config.ru create mode 100644 2345/3/controllers/application_controller.rb create mode 100644 2345/3/controllers/articles_controller.rb delete mode 100644 2345/3/mechanize_onliner_0.0.1.rb create mode 100644 2345/3/models/article.rb create mode 100644 2345/3/models/article_creater.rb rename 2345/3/{onliner_0.0.2 => models/article_parser.rb} (57%) create mode 100644 2345/3/models/comment.rb create mode 100644 2345/3/models/comment_parser.rb create mode 100644 2345/3/models/comments_rating.rb create mode 100644 2345/3/models/create_comments.rb create mode 100644 2345/3/models/pass create mode 100644 2345/3/models/rating_counter.rb create mode 100644 2345/3/views/articles/create.erb create mode 100644 2345/3/views/articles/edit.erb create mode 100644 2345/3/views/articles/index.erb create mode 100644 2345/3/views/articles/show.erb create mode 100644 2345/3/views/not_found.erb diff --git a/2345/3/.ruby-gemset b/2345/3/.ruby-gemset new file mode 100755 index 000000000..4717fea07 --- /dev/null +++ b/2345/3/.ruby-gemset @@ -0,0 +1 @@ +Onliner2345 diff --git a/2345/3/.ruby-version b/2345/3/.ruby-version new file mode 100755 index 000000000..bf080da67 --- /dev/null +++ b/2345/3/.ruby-version @@ -0,0 +1 @@ +ruby-2.5.0 diff --git a/2345/3/Gemfile b/2345/3/Gemfile index 553533d96..afba47f19 100755 --- a/2345/3/Gemfile +++ b/2345/3/Gemfile @@ -1,11 +1,13 @@ 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' +gem 'mechanize', '~> 2.7', '>= 2.7.6' gem 'ohm', '~> 3.1', '>= 3.1.1' -gem 'mechanize', '~> 2.7', '>= 2.7.6' # https://rubygems.org/gems/mechanize -# gem 'capybara', '~> 3.4', '>= 3.4.2' # https://rubygems.org/gems/capybara -gem 'shotgun', '~> 0.9.2' +gem 'redis', '~> 3.3', '>= 3.3.1' +gem 'sinatra', '~> 1.4', '>= 1.4.7' + +group :development do + gem 'pry' + gem 'reek' + gem 'rubocop', '~> 0.54.0' + gem 'shotgun', '~> 0.9.2' +end diff --git a/2345/3/Gemfile.lock b/2345/3/Gemfile.lock index 231c944a4..4c43016e4 100644 --- a/2345/3/Gemfile.lock +++ b/2345/3/Gemfile.lock @@ -8,6 +8,7 @@ GEM thread_safe (~> 0.3, >= 0.3.1) codeclimate-engine-rb (0.4.1) virtus (~> 1.0) + coderay (1.1.2) coercible (1.0.0) descendants_tracker (~> 0.0.1) connection_pool (2.2.2) @@ -30,6 +31,7 @@ GEM nokogiri (~> 1.6) ntlm-http (~> 0.1, >= 0.1.1) webrobots (>= 0.0.9, < 0.2) + method_source (0.9.0) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) @@ -50,6 +52,9 @@ GEM parser (2.5.1.2) ast (~> 2.4.0) powerpack (0.1.2) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) rack (1.6.10) rack-protection (1.5.5) rack @@ -97,6 +102,7 @@ PLATFORMS DEPENDENCIES mechanize (~> 2.7, >= 2.7.6) ohm (~> 3.1, >= 3.1.1) + pry redis (~> 3.3, >= 3.3.1) reek rubocop (~> 0.54.0) @@ -104,4 +110,4 @@ DEPENDENCIES sinatra (~> 1.4, >= 1.4.7) BUNDLED WITH - 1.16.1 + 1.16.3 diff --git a/2345/3/config.ru b/2345/3/config.ru new file mode 100644 index 000000000..d8c1fe051 --- /dev/null +++ b/2345/3/config.ru @@ -0,0 +1,6 @@ +Bundler.require + +Dir.glob('./{controllers,models}/*.rb').each { |file| require_relative file } + +map('/articles') { run ArticlesController } +map('/') { run ApplicationController } diff --git a/2345/3/controllers/application_controller.rb b/2345/3/controllers/application_controller.rb new file mode 100644 index 000000000..a83f1b3b0 --- /dev/null +++ b/2345/3/controllers/application_controller.rb @@ -0,0 +1,12 @@ +class ApplicationController < Sinatra::Base + set :views, File.expand_path(File.join(__FILE__, '../../views')) + set :method_override, true + + not_found do + erb :not_found + end + + get '/' do + redirect to '/articles' + end +end diff --git a/2345/3/controllers/articles_controller.rb b/2345/3/controllers/articles_controller.rb new file mode 100644 index 000000000..049b3323d --- /dev/null +++ b/2345/3/controllers/articles_controller.rb @@ -0,0 +1,39 @@ +require_relative './application_controller.rb' + +class ArticlesController < ApplicationController + get '/' do + @articles = Article.all + erb :'/articles/index' + end + + get '/new' do + erb :'/articles/create' + end + + post '/' do + @article = ArticleCreater.new(params).create + redirect to '/' + end + + get '/:id' do + @article = Article[params[:id]] + @comments = @article.comments + erb :'/articles/show' + end + + get '/:id/edit' do + @article = Article[params[:id]] + erb :'articles/edit' + end + + delete '/:id' do + Article[params[:id]].delete + redirect to '/' + end + + post '/:id' do + @article = Article[params[:id]] + @article.update(link: params[:article]) + redirect to "/#{params[:id]}" + end +end diff --git a/2345/3/mechanize_onliner_0.0.1.rb b/2345/3/mechanize_onliner_0.0.1.rb deleted file mode 100644 index 7ad0a881c..000000000 --- a/2345/3/mechanize_onliner_0.0.1.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'mechanize' - -agent = Mechanize.new -page = agent.get('https://people.onliner.by/2018/07/23/vodol') - -# reviews = review_links.map do |link| - # review = page.click - review_meta = review.search('#main .review-meta .info') - artist = review_meta.search('h1')[0].text - album = review_meta.search('h2')[0].text - label, year = review_meta.search('h3')[0].text.split(';').map(&:strip) - reviewer = review_meta.search('h4 address')[0].text - review_date = Date.parse(review_meta.search('.pub-date')[0].text) - score = review_meta.search('.score').text.to_f - { - artist: artist, - album: album, - label: label, - year: year, - reviewer: reviewer, - review_date: review_date, - score: score - } -# end - -puts JSON.pretty_generate(reviews) \ No newline at end of file diff --git a/2345/3/models/article.rb b/2345/3/models/article.rb new file mode 100644 index 000000000..b608e6515 --- /dev/null +++ b/2345/3/models/article.rb @@ -0,0 +1,7 @@ +class Article < Ohm::Model + attribute :link + attribute :title + attribute :rating + unique :link + collection :comments, :Comment +end diff --git a/2345/3/models/article_creater.rb b/2345/3/models/article_creater.rb new file mode 100644 index 000000000..2893903b5 --- /dev/null +++ b/2345/3/models/article_creater.rb @@ -0,0 +1,28 @@ +class ArticleCreater + attr_reader :article + + def initialize(options) + @article_link = options[:article] + @comments = ArticleParser.new(@article_link).comments + end + + def create + @article = Article.create(link: @article_link, title: title, rating: article_rating) + CommentsCreater.new(comments_with_rating, article).create + article + end + + private + + def article_rating + comments_with_rating.map { |comment| comment[:rating] }.sum / @comments.size + end + + def comments_with_rating + CommentsRating.new(@comments).put_ratings + end + + def title + ArticleParser.new(@article_link).title + end +end diff --git a/2345/3/onliner_0.0.2 b/2345/3/models/article_parser.rb similarity index 57% rename from 2345/3/onliner_0.0.2 rename to 2345/3/models/article_parser.rb index 051940cef..4b475f287 100644 --- a/2345/3/onliner_0.0.2 +++ b/2345/3/models/article_parser.rb @@ -1,9 +1,7 @@ require 'mechanize' class ArticleParser - include CommentHelper - - def initialize(link = 'https://tech.onliner.by/2018/07/24/duglas-censor-martin') + def initialize(link = 'https://people.onliner.by/2018/07/23/vodol') @agent = Mechanize.new @article_link = link end @@ -14,9 +12,9 @@ def title def comments data['comments'].reverse.map do |comment| - { author: CommentHelper.author(comment), - text: CommentHelper.text(comment), - votes: CommentHelper.votes(comment) } + { author: CommentParser.author(comment), + text: CommentParser.text(comment), + votes: CommentParser.votes(comment) } end end @@ -38,19 +36,3 @@ 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 - - diff --git a/2345/3/models/comment.rb b/2345/3/models/comment.rb new file mode 100644 index 000000000..d5176d5fd --- /dev/null +++ b/2345/3/models/comment.rb @@ -0,0 +1,6 @@ +class Comment < Ohm::Model + attribute :author + attribute :text + attribute :rating + reference :article, :Article +end diff --git a/2345/3/models/comment_parser.rb b/2345/3/models/comment_parser.rb new file mode 100644 index 000000000..b4b3d2586 --- /dev/null +++ b/2345/3/models/comment_parser.rb @@ -0,0 +1,13 @@ +module CommentParser + 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 diff --git a/2345/3/models/comments_rating.rb b/2345/3/models/comments_rating.rb new file mode 100644 index 000000000..911812c41 --- /dev/null +++ b/2345/3/models/comments_rating.rb @@ -0,0 +1,23 @@ +class CommentsRating + LIMIT = 50 + + def initialize(comments) + @comments = comments + end + + # :reek:FeatureEnvy + def put_ratings + selected_for_evaluation = sort_comments_by_votes + ratings = RatingCounter.new(selected_for_evaluation).calculate + selected_for_evaluation.zip(ratings).map do |record| + record.first[:rating] = record.last + record[0] + end + end + + private + + def sort_comments_by_votes + @comments.sort_by { |comment| comment[:votes] }.reverse.first(LIMIT) + end +end diff --git a/2345/3/models/create_comments.rb b/2345/3/models/create_comments.rb new file mode 100644 index 000000000..75c979f30 --- /dev/null +++ b/2345/3/models/create_comments.rb @@ -0,0 +1,15 @@ +class CommentsCreater + LIMIT = 50 + + def initialize(comments, article) + @comments = comments + @article = article + end + + # :reek:FeatureEnvy + def create + @comments.each do |comment| + Comment.create(author: comment[:author], text: comment[:text], rating: comment[:rating], article: @article) + end + end +end diff --git a/2345/3/models/pass b/2345/3/models/pass new file mode 100644 index 000000000..0ec9698ee --- /dev/null +++ b/2345/3/models/pass @@ -0,0 +1 @@ +20841f572fe6442a808d3328479cf8fc \ No newline at end of file diff --git a/2345/3/models/rating_counter.rb b/2345/3/models/rating_counter.rb new file mode 100644 index 000000000..fa556f9d4 --- /dev/null +++ b/2345/3/models/rating_counter.rb @@ -0,0 +1,45 @@ +require 'net/https' +require 'uri' +require 'json' + +class RatingCounter + URI = 'https://westeurope.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment'.freeze + ACCESS_KEY = IO.read(File.dirname(__FILE__) + '/pass').freeze + attr_reader :request + + def initialize(comments) + @uri = URI(URI) + @data = { documents: [] } + @comments = comments + end + + def calculate + prepare_comments + @request = create_request + response = send_request + JSON.parse(response.body)['documents'].map do |data| + (data['score'] * 200).to_i - 100 + end + end + + private + + def send_request + Net::HTTP.start(@uri.host, @uri.port, use_ssl: @uri.scheme == 'https') do |http| + http.request(request) + end + end + + def prepare_comments + @comments.each_with_index do |comment, index| + @data[:documents] << { 'id' => index.to_s, 'language' => 'ru', 'text' => comment[:text] } + end + end + + def create_request + request = Net::HTTP::Post.new(@uri, 'Content-Type' => 'application/json', + 'Ocp-Apim-Subscription-Key' => ACCESS_KEY) + request.body = @data.to_json + request + end +end diff --git a/2345/3/views/articles/create.erb b/2345/3/views/articles/create.erb new file mode 100644 index 000000000..82615f6b2 --- /dev/null +++ b/2345/3/views/articles/create.erb @@ -0,0 +1,9 @@ +

New article

+ +
+
+ +
+ +
+ diff --git a/2345/3/views/articles/edit.erb b/2345/3/views/articles/edit.erb new file mode 100644 index 000000000..ec071f363 --- /dev/null +++ b/2345/3/views/articles/edit.erb @@ -0,0 +1,11 @@ +

Edit article

+ +
+
+ + + Link to be edited +
+ +
+ diff --git a/2345/3/views/articles/index.erb b/2345/3/views/articles/index.erb new file mode 100644 index 000000000..2eeec5462 --- /dev/null +++ b/2345/3/views/articles/index.erb @@ -0,0 +1,29 @@ + + + Articles table + + + New article + + + + + + + + + + + + <% @articles.each_with_index do |article, index| %> + + + + + + + <% end %> + +
#TitleRating
<%= index + 1 %>><%= article.title %><%= article.rating %> >>>>
+ + diff --git a/2345/3/views/articles/show.erb b/2345/3/views/articles/show.erb new file mode 100644 index 000000000..30c6e357d --- /dev/null +++ b/2345/3/views/articles/show.erb @@ -0,0 +1,28 @@ +
+

<%= @article.title %>

+
+ + | +
+ + +
+ + +

Comments

+ + diff --git a/2345/3/views/not_found.erb b/2345/3/views/not_found.erb new file mode 100644 index 000000000..09cbb7886 --- /dev/null +++ b/2345/3/views/not_found.erb @@ -0,0 +1,12 @@ +
+
+
+

Oops!

+

404 Not Found

+
+ Sorry, an error has occured, Requested page not found! +
+
+
+
+ From 71c4668b0fa2661426ea89e7936fd29f10fd489b Mon Sep 17 00:00:00 2001 From: Almix047 Date: Wed, 1 Aug 2018 17:46:36 +0000 Subject: [PATCH 3/3] Removed password Azure and small views changes --- 2345/3/controllers/articles_controller.rb | 5 -- 2345/3/models/pass | 1 - 2345/3/models/rating_counter.rb | 2 +- 2345/3/views/articles/create.erb | 23 ++++++--- 2345/3/views/articles/edit.erb | 11 ----- 2345/3/views/articles/index.erb | 10 ++-- 2345/3/views/articles/show.erb | 59 ++++++++++++++--------- 7 files changed, 57 insertions(+), 54 deletions(-) delete mode 100644 2345/3/models/pass delete mode 100644 2345/3/views/articles/edit.erb diff --git a/2345/3/controllers/articles_controller.rb b/2345/3/controllers/articles_controller.rb index 049b3323d..c82f61602 100644 --- a/2345/3/controllers/articles_controller.rb +++ b/2345/3/controllers/articles_controller.rb @@ -21,11 +21,6 @@ class ArticlesController < ApplicationController erb :'/articles/show' end - get '/:id/edit' do - @article = Article[params[:id]] - erb :'articles/edit' - end - delete '/:id' do Article[params[:id]].delete redirect to '/' diff --git a/2345/3/models/pass b/2345/3/models/pass deleted file mode 100644 index 0ec9698ee..000000000 --- a/2345/3/models/pass +++ /dev/null @@ -1 +0,0 @@ -20841f572fe6442a808d3328479cf8fc \ No newline at end of file diff --git a/2345/3/models/rating_counter.rb b/2345/3/models/rating_counter.rb index fa556f9d4..1c315a791 100644 --- a/2345/3/models/rating_counter.rb +++ b/2345/3/models/rating_counter.rb @@ -3,7 +3,7 @@ require 'json' class RatingCounter - URI = 'https://westeurope.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment'.freeze + URI = 'https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment'.freeze ACCESS_KEY = IO.read(File.dirname(__FILE__) + '/pass').freeze attr_reader :request diff --git a/2345/3/views/articles/create.erb b/2345/3/views/articles/create.erb index 82615f6b2..8ae520991 100644 --- a/2345/3/views/articles/create.erb +++ b/2345/3/views/articles/create.erb @@ -1,9 +1,16 @@ -

New article

- -
-
- -
- -
+ + + Adding an article + +

New article

+ + +
+
+ +
+ +
+ + diff --git a/2345/3/views/articles/edit.erb b/2345/3/views/articles/edit.erb deleted file mode 100644 index ec071f363..000000000 --- a/2345/3/views/articles/edit.erb +++ /dev/null @@ -1,11 +0,0 @@ -

Edit article

- -
-
- - - Link to be edited -
- -
- diff --git a/2345/3/views/articles/index.erb b/2345/3/views/articles/index.erb index 2eeec5462..feff80752 100644 --- a/2345/3/views/articles/index.erb +++ b/2345/3/views/articles/index.erb @@ -1,12 +1,14 @@ - Articles table + Table with analyzed articles - New article +

New article

+ +

Table with analyzed articles

- +
@@ -25,5 +27,5 @@ <% end %>
#
+ - diff --git a/2345/3/views/articles/show.erb b/2345/3/views/articles/show.erb index 30c6e357d..cc245fe9f 100644 --- a/2345/3/views/articles/show.erb +++ b/2345/3/views/articles/show.erb @@ -1,28 +1,39 @@ -
-

<%= @article.title %>

-
+ + + Comments + - | -
- - -
+
+

<%= @article.title %>

+
+ | +
+ + +
-

Comments

+

Comments of the selected article

-
    - <% @comments.each do |comment| %> -
  • -
    -
    -

    <%= comment.author %>

    -

    - <%= comment.text %> -

    -
    Рейтинг: <%= comment.rating %>
    -
    -
    -
  • - <% end %> -
+ + + + + + + + + <% @comments.each do |comment| %> + + + + + <% end %> + +
Comment + Rating
+

<%= comment.author %>

+ <%= comment.text %> +
<%= comment.rating %>
+ +