{"action":"created","comment":{"url":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/comments/50670823","id":50670823,"diff_hunk":"@@ -1,51 +1,32 @@\n-require 'curb'\n-require 'nokogiri'\n-require 'json'\n-require 'uri'\n require 'dotenv'\n+require './slack_client'\n+require './uvo_scraper'\n \n Dotenv.load!\n \n-SEARCH_URL = 'https://www2.uvo.gov.sk/evestnik?p_p_id=evestnik_WAR_eVestnikPortlets&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-2&p_p_col_pos=1&p_p_col_count=2'\n-NEW_ISSUE_URL = 'https://www2.uvo.gov.sk/evestnik/-/vestnik/aktual'\n-\n-def send_message(text)\n-  payload = { text: text, channel: '#general', username: 'uvobot', icon_emoji: ':mag_right:' }\n-  Curl.post(ENV['UVOBOT_SLACK_WEBHOOK'], payload.to_json)\n-end\n-\n-def issue_ready?\n-  html = Curl.get(NEW_ISSUE_URL).body\n-  header = Nokogiri::HTML.parse(html).css('h1')[1]\n-  identifier = Time.now.strftime('/%Y - %-d.%-m.%Y')\n-  header.text.include?(identifier)\n-end\n-\n-unless issue_ready?\n-  send_message('*Fíha, dnes na ÚVO nevyšlo nové vydanie vestníka?*')\n-  exit\n-end\n-\n-today = Time.now.strftime('%d.%m.%Y')\n-vars = { cpv: 72, datumZverejneniaOd: today, datumZverejneniaDo: today}\n-\n-html = Curl.post(SEARCH_URL, vars).body\n-doc = Nokogiri::HTML.parse(html)\n-\n-rows = doc.css('.oznamenie')\n-\n-if rows.count == 0 \n-  send_message('Dnes som nenašiel žiadne nové IT zákazky.')\n-else\n-  counter = doc.css('.search-results').first.text\n-  send_message(\"Našiel niečo nové na ÚVO! #{counter}\")\n+class Uvobot\n+  def initialize(urls)\n+    @slack = SlackClient.new(slack_webhook: ENV['UVOBOT_SLACK_WEBHOOK'])\n+    @scraper = UvoScraper.new(urls)\n+  end\n+\n+  def update\n+     if @scraper.issue_ready?\n+       announcements = @scraper.announcements\n+       @slack.send_message(\"Našiel som niečo nové na ÚVO!\") if announcements.count > 0\n+\n+       announcements.each do |a|\n+         @slack.send_message(\"<#{a[:link][:href]}|#{a[:link][:text]}>: *#{a[:customer]}* #{a[:description]}\")\n+       end\n+     else\n+       @slack.send_message('*Fíha, dnes na ÚVO nevyšlo nové vydanie vestníka?*')\n+     end\n+  end\n end\n \n-rows.each do |row|\n-  link = row.css('.ozn1 a').first\n-  customer = row.css('.ozn2').text.strip\n-  description = row.css('.ozn3').text.strip\n-\n-  send_message(\"<#{link['href']}|#{link.text}>: *#{customer}* #{description}\")\n-end\n+urls = {\n+  search:  'https://www2.uvo.gov.sk/evestnik?p_p_id=evestnik_WAR_eVestnikPortlets&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-2&p_p_col_pos=1&p_p_col_count=2',\n+  new_issue: 'https://www2.uvo.gov.sk/evestnik/-/vestnik/aktual'\n+}\n \n+Uvobot.new(urls).update","path":"uvobot.rb","position":76,"original_position":76,"commit_id":"14ab4638c0a1abbaea95375a4f23763f94657a46","original_commit_id":"14ab4638c0a1abbaea95375a4f23763f94657a46","user":{"login":"martinsabo","id":2777926,"avatar_url":"https://avatars.githubusercontent.com/u/2777926?v=3","gravatar_id":"","url":"https://api.github.com/users/martinsabo","html_url":"https://github.com/martinsabo","followers_url":"https://api.github.com/users/martinsabo/followers","following_url":"https://api.github.com/users/martinsabo/following{/other_user}","gists_url":"https://api.github.com/users/martinsabo/gists{/gist_id}","starred_url":"https://api.github.com/users/martinsabo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinsabo/subscriptions","organizations_url":"https://api.github.com/users/martinsabo/orgs","repos_url":"https://api.github.com/users/martinsabo/repos","events_url":"https://api.github.com/users/martinsabo/events{/privacy}","received_events_url":"https://api.github.com/users/martinsabo/received_events","type":"User","site_admin":false},"body":"Páči sa mi to. Zapracujem.","created_at":"2016-01-25T09:35:00Z","updated_at":"2016-01-25T09:35:00Z","html_url":"https://github.com/slovensko-digital/uvobot/pull/5#discussion_r50670823","pull_request_url":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/comments/50670823"},"html":{"href":"https://github.com/slovensko-digital/uvobot/pull/5#discussion_r50670823"},"pull_request":{"href":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/5","id":57039540,"html_url":"https://github.com/slovensko-digital/uvobot/pull/5","diff_url":"https://github.com/slovensko-digital/uvobot/pull/5.diff","patch_url":"https://github.com/slovensko-digital/uvobot/pull/5.patch","issue_url":"https://api.github.com/repos/slovensko-digital/uvobot/issues/5","number":5,"state":"open","locked":false,"title":"Refactoring/Class extraction and general cleanup.","user":{"login":"martinsabo","id":2777926,"avatar_url":"https://avatars.githubusercontent.com/u/2777926?v=3","gravatar_id":"","url":"https://api.github.com/users/martinsabo","html_url":"https://github.com/martinsabo","followers_url":"https://api.github.com/users/martinsabo/followers","following_url":"https://api.github.com/users/martinsabo/following{/other_user}","gists_url":"https://api.github.com/users/martinsabo/gists{/gist_id}","starred_url":"https://api.github.com/users/martinsabo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinsabo/subscriptions","organizations_url":"https://api.github.com/users/martinsabo/orgs","repos_url":"https://api.github.com/users/martinsabo/repos","events_url":"https://api.github.com/users/martinsabo/events{/privacy}","received_events_url":"https://api.github.com/users/martinsabo/received_events","type":"User","site_admin":false},"body":"Trochu som Uvobota upratal (ako prípravu pre Discourse posting). A mierne zmenil texty (odstránený counter). Pripomienky sú vítané.","created_at":"2016-01-25T08:13:46Z","updated_at":"2016-01-25T09:35:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"df726df43c39e1f0868100d77db9439d3b10f03c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/5/commits","review_comments_url":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/5/comments","review_comment_url":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/slovensko-digital/uvobot/issues/5/comments","statuses_url":"https://api.github.com/repos/slovensko-digital/uvobot/statuses/14ab4638c0a1abbaea95375a4f23763f94657a46","head":{"label":"martinsabo:master","ref":"master","sha":"14ab4638c0a1abbaea95375a4f23763f94657a46","user":{"login":"martinsabo","id":2777926,"avatar_url":"https://avatars.githubusercontent.com/u/2777926?v=3","gravatar_id":"","url":"https://api.github.com/users/martinsabo","html_url":"https://github.com/martinsabo","followers_url":"https://api.github.com/users/martinsabo/followers","following_url":"https://api.github.com/users/martinsabo/following{/other_user}","gists_url":"https://api.github.com/users/martinsabo/gists{/gist_id}","starred_url":"https://api.github.com/users/martinsabo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinsabo/subscriptions","organizations_url":"https://api.github.com/users/martinsabo/orgs","repos_url":"https://api.github.com/users/martinsabo/repos","events_url":"https://api.github.com/users/martinsabo/events{/privacy}","received_events_url":"https://api.github.com/users/martinsabo/received_events","type":"User","site_admin":false},"repo":{"id":50290533,"name":"uvobot","full_name":"martinsabo/uvobot","owner":{"login":"martinsabo","id":2777926,"avatar_url":"https://avatars.githubusercontent.com/u/2777926?v=3","gravatar_id":"","url":"https://api.github.com/users/martinsabo","html_url":"https://github.com/martinsabo","followers_url":"https://api.github.com/users/martinsabo/followers","following_url":"https://api.github.com/users/martinsabo/following{/other_user}","gists_url":"https://api.github.com/users/martinsabo/gists{/gist_id}","starred_url":"https://api.github.com/users/martinsabo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinsabo/subscriptions","organizations_url":"https://api.github.com/users/martinsabo/orgs","repos_url":"https://api.github.com/users/martinsabo/repos","events_url":"https://api.github.com/users/martinsabo/events{/privacy}","received_events_url":"https://api.github.com/users/martinsabo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/martinsabo/uvobot","description":"","fork":true,"url":"https://api.github.com/repos/martinsabo/uvobot","forks_url":"https://api.github.com/repos/martinsabo/uvobot/forks","keys_url":"https://api.github.com/repos/martinsabo/uvobot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/martinsabo/uvobot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/martinsabo/uvobot/teams","hooks_url":"https://api.github.com/repos/martinsabo/uvobot/hooks","issue_events_url":"https://api.github.com/repos/martinsabo/uvobot/issues/events{/number}","events_url":"https://api.github.com/repos/martinsabo/uvobot/events","assignees_url":"https://api.github.com/repos/martinsabo/uvobot/assignees{/user}","branches_url":"https://api.github.com/repos/martinsabo/uvobot/branches{/branch}","tags_url":"https://api.github.com/repos/martinsabo/uvobot/tags","blobs_url":"https://api.github.com/repos/martinsabo/uvobot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/martinsabo/uvobot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/martinsabo/uvobot/git/refs{/sha}","trees_url":"https://api.github.com/repos/martinsabo/uvobot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/martinsabo/uvobot/statuses/{sha}","languages_url":"https://api.github.com/repos/martinsabo/uvobot/languages","stargazers_url":"https://api.github.com/repos/martinsabo/uvobot/stargazers","contributors_url":"https://api.github.com/repos/martinsabo/uvobot/contributors","subscribers_url":"https://api.github.com/repos/martinsabo/uvobot/subscribers","subscription_url":"https://api.github.com/repos/martinsabo/uvobot/subscription","commits_url":"https://api.github.com/repos/martinsabo/uvobot/commits{/sha}","git_commits_url":"https://api.github.com/repos/martinsabo/uvobot/git/commits{/sha}","comments_url":"https://api.github.com/repos/martinsabo/uvobot/comments{/number}","issue_comment_url":"https://api.github.com/repos/martinsabo/uvobot/issues/comments{/number}","contents_url":"https://api.github.com/repos/martinsabo/uvobot/contents/{+path}","compare_url":"https://api.github.com/repos/martinsabo/uvobot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/martinsabo/uvobot/merges","archive_url":"https://api.github.com/repos/martinsabo/uvobot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/martinsabo/uvobot/downloads","issues_url":"https://api.github.com/repos/martinsabo/uvobot/issues{/number}","pulls_url":"https://api.github.com/repos/martinsabo/uvobot/pulls{/number}","milestones_url":"https://api.github.com/repos/martinsabo/uvobot/milestones{/number}","notifications_url":"https://api.github.com/repos/martinsabo/uvobot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/martinsabo/uvobot/labels{/name}","releases_url":"https://api.github.com/repos/martinsabo/uvobot/releases{/id}","deployments_url":"https://api.github.com/repos/martinsabo/uvobot/deployments","created_at":"2016-01-24T14:11:42Z","updated_at":"2016-01-24T14:11:43Z","pushed_at":"2016-01-25T08:05:33Z","git_url":"git://github.com/martinsabo/uvobot.git","ssh_url":"git@github.com:martinsabo/uvobot.git","clone_url":"https://github.com/martinsabo/uvobot.git","svn_url":"https://github.com/martinsabo/uvobot","homepage":null,"size":6,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"slovensko-digital:master","ref":"master","sha":"ebf59f49ee5d297aa5470ee6d2f9f235903f54d9","user":{"login":"slovensko-digital","id":16101866,"avatar_url":"https://avatars.githubusercontent.com/u/16101866?v=3","gravatar_id":"","url":"https://api.github.com/users/slovensko-digital","html_url":"https://github.com/slovensko-digital","followers_url":"https://api.github.com/users/slovensko-digital/followers","following_url":"https://api.github.com/users/slovensko-digital/following{/other_user}","gists_url":"https://api.github.com/users/slovensko-digital/gists{/gist_id}","starred_url":"https://api.github.com/users/slovensko-digital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slovensko-digital/subscriptions","organizations_url":"https://api.github.com/users/slovensko-digital/orgs","repos_url":"https://api.github.com/users/slovensko-digital/repos","events_url":"https://api.github.com/users/slovensko-digital/events{/privacy}","received_events_url":"https://api.github.com/users/slovensko-digital/received_events","type":"Organization","site_admin":false},"repo":{"id":48381109,"name":"uvobot","full_name":"slovensko-digital/uvobot","owner":{"login":"slovensko-digital","id":16101866,"avatar_url":"https://avatars.githubusercontent.com/u/16101866?v=3","gravatar_id":"","url":"https://api.github.com/users/slovensko-digital","html_url":"https://github.com/slovensko-digital","followers_url":"https://api.github.com/users/slovensko-digital/followers","following_url":"https://api.github.com/users/slovensko-digital/following{/other_user}","gists_url":"https://api.github.com/users/slovensko-digital/gists{/gist_id}","starred_url":"https://api.github.com/users/slovensko-digital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slovensko-digital/subscriptions","organizations_url":"https://api.github.com/users/slovensko-digital/orgs","repos_url":"https://api.github.com/users/slovensko-digital/repos","events_url":"https://api.github.com/users/slovensko-digital/events{/privacy}","received_events_url":"https://api.github.com/users/slovensko-digital/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/slovensko-digital/uvobot","description":"","fork":false,"url":"https://api.github.com/repos/slovensko-digital/uvobot","forks_url":"https://api.github.com/repos/slovensko-digital/uvobot/forks","keys_url":"https://api.github.com/repos/slovensko-digital/uvobot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/slovensko-digital/uvobot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/slovensko-digital/uvobot/teams","hooks_url":"https://api.github.com/repos/slovensko-digital/uvobot/hooks","issue_events_url":"https://api.github.com/repos/slovensko-digital/uvobot/issues/events{/number}","events_url":"https://api.github.com/repos/slovensko-digital/uvobot/events","assignees_url":"https://api.github.com/repos/slovensko-digital/uvobot/assignees{/user}","branches_url":"https://api.github.com/repos/slovensko-digital/uvobot/branches{/branch}","tags_url":"https://api.github.com/repos/slovensko-digital/uvobot/tags","blobs_url":"https://api.github.com/repos/slovensko-digital/uvobot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/slovensko-digital/uvobot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/slovensko-digital/uvobot/git/refs{/sha}","trees_url":"https://api.github.com/repos/slovensko-digital/uvobot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/slovensko-digital/uvobot/statuses/{sha}","languages_url":"https://api.github.com/repos/slovensko-digital/uvobot/languages","stargazers_url":"https://api.github.com/repos/slovensko-digital/uvobot/stargazers","contributors_url":"https://api.github.com/repos/slovensko-digital/uvobot/contributors","subscribers_url":"https://api.github.com/repos/slovensko-digital/uvobot/subscribers","subscription_url":"https://api.github.com/repos/slovensko-digital/uvobot/subscription","commits_url":"https://api.github.com/repos/slovensko-digital/uvobot/commits{/sha}","git_commits_url":"https://api.github.com/repos/slovensko-digital/uvobot/git/commits{/sha}","comments_url":"https://api.github.com/repos/slovensko-digital/uvobot/comments{/number}","issue_comment_url":"https://api.github.com/repos/slovensko-digital/uvobot/issues/comments{/number}","contents_url":"https://api.github.com/repos/slovensko-digital/uvobot/contents/{+path}","compare_url":"https://api.github.com/repos/slovensko-digital/uvobot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/slovensko-digital/uvobot/merges","archive_url":"https://api.github.com/repos/slovensko-digital/uvobot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/slovensko-digital/uvobot/downloads","issues_url":"https://api.github.com/repos/slovensko-digital/uvobot/issues{/number}","pulls_url":"https://api.github.com/repos/slovensko-digital/uvobot/pulls{/number}","milestones_url":"https://api.github.com/repos/slovensko-digital/uvobot/milestones{/number}","notifications_url":"https://api.github.com/repos/slovensko-digital/uvobot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/slovensko-digital/uvobot/labels{/name}","releases_url":"https://api.github.com/repos/slovensko-digital/uvobot/releases{/id}","deployments_url":"https://api.github.com/repos/slovensko-digital/uvobot/deployments","created_at":"2015-12-21T16:07:11Z","updated_at":"2016-01-21T20:22:50Z","pushed_at":"2016-01-25T08:13:46Z","git_url":"git://github.com/slovensko-digital/uvobot.git","ssh_url":"git@github.com:slovensko-digital/uvobot.git","clone_url":"https://github.com/slovensko-digital/uvobot.git","svn_url":"https://github.com/slovensko-digital/uvobot","homepage":null,"size":4,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/5"},"html":{"href":"https://github.com/slovensko-digital/uvobot/pull/5"},"issue":{"href":"https://api.github.com/repos/slovensko-digital/uvobot/issues/5"},"comments":{"href":"https://api.github.com/repos/slovensko-digital/uvobot/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/slovensko-digital/uvobot/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/slovensko-digital/uvobot/statuses/14ab4638c0a1abbaea95375a4f23763f94657a46"}}}}