{"action":"created","comment":{"url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/comments/136554116","pull_request_review_id":60109524,"id":136554116,"diff_hunk":"@@ -0,0 +1,107 @@\n+package com.blackbook.matrasscraper.scraper;\n+\n+import com.blackbook.matrasscraper.htmlprovider.HTMLDocumentProvider;\n+import com.blackbook.matrasscraper.htmlprovider.JsoupHTMLDocumentProvider;\n+import lombok.extern.slf4j.Slf4j;\n+import org.jsoup.nodes.Document;\n+import org.jsoup.nodes.Element;\n+import org.jsoup.select.Elements;\n+import org.springframework.beans.factory.annotation.Value;\n+import org.springframework.context.annotation.Configuration;\n+import org.springframework.context.annotation.PropertySource;\n+import org.springframework.stereotype.Component;\n+import org.springframework.stereotype.Controller;\n+import view.creation_model.BookData;\n+import view.creation_model.BookDiscountData;\n+\n+import java.util.LinkedList;\n+import java.util.List;\n+import java.util.stream.Collectors;\n+\n+/**\n+ * @author \"Patrycja Zaremba\"\n+ */\n+@Slf4j\n+public class Scraper {\n+\n+    private final static String MATRAS_URL = \"http://www.matras.pl/ksiazki/promocje,k,53\";\n+    private final static String MATRAS_URL_PAGE = MATRAS_URL + \"?p=\";\n+    private final static int BOOKSTORE_ID = 1;\n+    private HTMLDocumentProvider htmlDocumentProvider;\n+\n+    public Scraper(HTMLDocumentProvider htmlDocumentProvider) {\n+        this.htmlDocumentProvider = htmlDocumentProvider;\n+    }\n+\n+    public static void main(String[] args) {\n+        Scraper scraper = new Scraper(new JsoupHTMLDocumentProvider());\n+        scraper.extractBookElements();\n+    }\n+\n+    public List<BookDiscountData> extractBookElements() {\n+        Document mainPageDoc = htmlDocumentProvider.provide(MATRAS_URL);\n+        int lastPageNo = extractLastPageNo(mainPageDoc);\n+        List<BookDiscountData> bookDiscountData = new LinkedList<>();\n+        //TODO change 1 to property or lastPageNo if all pages wanted\n+        for (int i = 0; i < 1; i++) {\n+            Document pageDoc = htmlDocumentProvider.provide(MATRAS_URL_PAGE + i);\n+            bookDiscountData.addAll(extractBookElementsFromSinglePage(pageDoc));\n+        }\n+        return bookDiscountData;\n+    }\n+\n+    private int extractLastPageNo(Document mainPageDoc) {\n+        return Integer.parseInt(mainPageDoc.select(\"ul.pagination-list > li:not(.next)\")\n+                    .last()\n+                    .text());\n+    }\n+\n+    private List<BookDiscountData> extractBookElementsFromSinglePage(Document document) {\n+        Elements bookElements = document.getElementsByClass(\"s-item eqh\");\n+        List<BookDiscountData> bookDiscountData = bookElements.stream()\n+                .map(bookElement -> {\n+                    String bookUrl = extractBookUrl(bookElement);\n+                    BookDocument bookDoc = new BookDocument(htmlDocumentProvider.provide(bookUrl));\n+                    return createBookDiscountData(bookDoc, bookUrl);\n+                })\n+                .collect(Collectors.toList());\n+        return bookDiscountData;\n+    }\n+\n+    private BookDiscountData createBookDiscountData(BookDocument bookDoc, String bookUrl) {\n+        String title = bookDoc.extractBookTitle();\n+        String subtitle = bookDoc.extractBookSubtitle();\n+        String authors = bookDoc.extractBookAuthors();\n+        String genre = bookDoc.extractBookGenre();\n+        Double price = bookDoc.extractBookPrice();\n+        String promoDetails = bookDoc.extractBookPromoDetails();\n+        String coverUrl = bookDoc.extractBookCoverUrl();\n+\n+        BookDiscountData bookDiscountData = BookDiscountData.builder()\n+                .bookstoreId(BOOKSTORE_ID)\n+                .price(price)\n+                .bookDiscountDetails(promoDetails)\n+                .bookData(BookData.builder()\n+                        .title(title)\n+                        .subtitle(subtitle)\n+                        .authors(authors)\n+                        .genre(genre)\n+                        .bookPageUrl(bookUrl)\n+                        .coverUrl(coverUrl)\n+                        .build())\n+                .build();\n+\n+        String separator = \" - \";","path":"matras_scraper/src/main/java/com/blackbook/matrasscraper/scraper/Scraper.java","position":94,"original_position":94,"commit_id":"9c4086f11c122bdd27cfec46c72f4b715fc4e46a","original_commit_id":"9c4086f11c122bdd27cfec46c72f4b715fc4e46a","user":{"login":"Devas","id":9119159,"avatar_url":"https://avatars2.githubusercontent.com/u/9119159?v=4","gravatar_id":"","url":"https://api.github.com/users/Devas","html_url":"https://github.com/Devas","followers_url":"https://api.github.com/users/Devas/followers","following_url":"https://api.github.com/users/Devas/following{/other_user}","gists_url":"https://api.github.com/users/Devas/gists{/gist_id}","starred_url":"https://api.github.com/users/Devas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Devas/subscriptions","organizations_url":"https://api.github.com/users/Devas/orgs","repos_url":"https://api.github.com/users/Devas/repos","events_url":"https://api.github.com/users/Devas/events{/privacy}","received_events_url":"https://api.github.com/users/Devas/received_events","type":"User","site_admin":false},"body":"👍 ","created_at":"2017-09-01T11:29:07Z","updated_at":"2017-09-01T11:34:07Z","html_url":"https://github.com/Tymoteuszauke/black-book-bot/pull/37#discussion_r136554116","pull_request_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/37","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/comments/136554116"},"html":{"href":"https://github.com/Tymoteuszauke/black-book-bot/pull/37#discussion_r136554116"},"pull_request":{"href":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/37"}}},"pull_request":{"url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/37","id":138865047,"html_url":"https://github.com/Tymoteuszauke/black-book-bot/pull/37","diff_url":"https://github.com/Tymoteuszauke/black-book-bot/pull/37.diff","patch_url":"https://github.com/Tymoteuszauke/black-book-bot/pull/37.patch","issue_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues/37","number":37,"state":"open","locked":false,"title":"Matras integration","user":{"login":"patkkka","id":28982992,"avatar_url":"https://avatars2.githubusercontent.com/u/28982992?v=4","gravatar_id":"","url":"https://api.github.com/users/patkkka","html_url":"https://github.com/patkkka","followers_url":"https://api.github.com/users/patkkka/followers","following_url":"https://api.github.com/users/patkkka/following{/other_user}","gists_url":"https://api.github.com/users/patkkka/gists{/gist_id}","starred_url":"https://api.github.com/users/patkkka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patkkka/subscriptions","organizations_url":"https://api.github.com/users/patkkka/orgs","repos_url":"https://api.github.com/users/patkkka/repos","events_url":"https://api.github.com/users/patkkka/events{/privacy}","received_events_url":"https://api.github.com/users/patkkka/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-09-01T10:53:48Z","updated_at":"2017-09-01T11:34:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab19ebd4cceb94e3914ad4104893c9286400e48a","assignee":null,"assignees":[],"requested_reviewers":[{"login":"paulstarbi","id":25307742,"avatar_url":"https://avatars3.githubusercontent.com/u/25307742?v=4","gravatar_id":"","url":"https://api.github.com/users/paulstarbi","html_url":"https://github.com/paulstarbi","followers_url":"https://api.github.com/users/paulstarbi/followers","following_url":"https://api.github.com/users/paulstarbi/following{/other_user}","gists_url":"https://api.github.com/users/paulstarbi/gists{/gist_id}","starred_url":"https://api.github.com/users/paulstarbi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulstarbi/subscriptions","organizations_url":"https://api.github.com/users/paulstarbi/orgs","repos_url":"https://api.github.com/users/paulstarbi/repos","events_url":"https://api.github.com/users/paulstarbi/events{/privacy}","received_events_url":"https://api.github.com/users/paulstarbi/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/37/commits","review_comments_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/37/comments","review_comment_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues/37/comments","statuses_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/statuses/9c4086f11c122bdd27cfec46c72f4b715fc4e46a","head":{"label":"Tymoteuszauke:matras_integration","ref":"matras_integration","sha":"9c4086f11c122bdd27cfec46c72f4b715fc4e46a","user":{"login":"Tymoteuszauke","id":15235314,"avatar_url":"https://avatars1.githubusercontent.com/u/15235314?v=4","gravatar_id":"","url":"https://api.github.com/users/Tymoteuszauke","html_url":"https://github.com/Tymoteuszauke","followers_url":"https://api.github.com/users/Tymoteuszauke/followers","following_url":"https://api.github.com/users/Tymoteuszauke/following{/other_user}","gists_url":"https://api.github.com/users/Tymoteuszauke/gists{/gist_id}","starred_url":"https://api.github.com/users/Tymoteuszauke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tymoteuszauke/subscriptions","organizations_url":"https://api.github.com/users/Tymoteuszauke/orgs","repos_url":"https://api.github.com/users/Tymoteuszauke/repos","events_url":"https://api.github.com/users/Tymoteuszauke/events{/privacy}","received_events_url":"https://api.github.com/users/Tymoteuszauke/received_events","type":"User","site_admin":false},"repo":{"id":100492943,"name":"black-book-bot","full_name":"Tymoteuszauke/black-book-bot","owner":{"login":"Tymoteuszauke","id":15235314,"avatar_url":"https://avatars1.githubusercontent.com/u/15235314?v=4","gravatar_id":"","url":"https://api.github.com/users/Tymoteuszauke","html_url":"https://github.com/Tymoteuszauke","followers_url":"https://api.github.com/users/Tymoteuszauke/followers","following_url":"https://api.github.com/users/Tymoteuszauke/following{/other_user}","gists_url":"https://api.github.com/users/Tymoteuszauke/gists{/gist_id}","starred_url":"https://api.github.com/users/Tymoteuszauke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tymoteuszauke/subscriptions","organizations_url":"https://api.github.com/users/Tymoteuszauke/orgs","repos_url":"https://api.github.com/users/Tymoteuszauke/repos","events_url":"https://api.github.com/users/Tymoteuszauke/events{/privacy}","received_events_url":"https://api.github.com/users/Tymoteuszauke/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Tymoteuszauke/black-book-bot","description":"Robot application for Java Academy","fork":false,"url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot","forks_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/forks","keys_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/teams","hooks_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/hooks","issue_events_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues/events{/number}","events_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/events","assignees_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/assignees{/user}","branches_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/branches{/branch}","tags_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/tags","blobs_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/statuses/{sha}","languages_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/languages","stargazers_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/stargazers","contributors_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/contributors","subscribers_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/subscribers","subscription_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/subscription","commits_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/contents/{+path}","compare_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/merges","archive_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/downloads","issues_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues{/number}","pulls_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls{/number}","milestones_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/milestones{/number}","notifications_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/labels{/name}","releases_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/releases{/id}","deployments_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/deployments","created_at":"2017-08-16T13:33:50Z","updated_at":"2017-08-22T07:35:47Z","pushed_at":"2017-09-01T10:53:48Z","git_url":"git://github.com/Tymoteuszauke/black-book-bot.git","ssh_url":"git@github.com:Tymoteuszauke/black-book-bot.git","clone_url":"https://github.com/Tymoteuszauke/black-book-bot.git","svn_url":"https://github.com/Tymoteuszauke/black-book-bot","homepage":null,"size":208,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"development"}},"base":{"label":"Tymoteuszauke:development","ref":"development","sha":"6e45230f59ffce200861177ec91de8488a834234","user":{"login":"Tymoteuszauke","id":15235314,"avatar_url":"https://avatars1.githubusercontent.com/u/15235314?v=4","gravatar_id":"","url":"https://api.github.com/users/Tymoteuszauke","html_url":"https://github.com/Tymoteuszauke","followers_url":"https://api.github.com/users/Tymoteuszauke/followers","following_url":"https://api.github.com/users/Tymoteuszauke/following{/other_user}","gists_url":"https://api.github.com/users/Tymoteuszauke/gists{/gist_id}","starred_url":"https://api.github.com/users/Tymoteuszauke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tymoteuszauke/subscriptions","organizations_url":"https://api.github.com/users/Tymoteuszauke/orgs","repos_url":"https://api.github.com/users/Tymoteuszauke/repos","events_url":"https://api.github.com/users/Tymoteuszauke/events{/privacy}","received_events_url":"https://api.github.com/users/Tymoteuszauke/received_events","type":"User","site_admin":false},"repo":{"id":100492943,"name":"black-book-bot","full_name":"Tymoteuszauke/black-book-bot","owner":{"login":"Tymoteuszauke","id":15235314,"avatar_url":"https://avatars1.githubusercontent.com/u/15235314?v=4","gravatar_id":"","url":"https://api.github.com/users/Tymoteuszauke","html_url":"https://github.com/Tymoteuszauke","followers_url":"https://api.github.com/users/Tymoteuszauke/followers","following_url":"https://api.github.com/users/Tymoteuszauke/following{/other_user}","gists_url":"https://api.github.com/users/Tymoteuszauke/gists{/gist_id}","starred_url":"https://api.github.com/users/Tymoteuszauke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tymoteuszauke/subscriptions","organizations_url":"https://api.github.com/users/Tymoteuszauke/orgs","repos_url":"https://api.github.com/users/Tymoteuszauke/repos","events_url":"https://api.github.com/users/Tymoteuszauke/events{/privacy}","received_events_url":"https://api.github.com/users/Tymoteuszauke/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Tymoteuszauke/black-book-bot","description":"Robot application for Java Academy","fork":false,"url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot","forks_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/forks","keys_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/teams","hooks_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/hooks","issue_events_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues/events{/number}","events_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/events","assignees_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/assignees{/user}","branches_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/branches{/branch}","tags_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/tags","blobs_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/statuses/{sha}","languages_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/languages","stargazers_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/stargazers","contributors_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/contributors","subscribers_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/subscribers","subscription_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/subscription","commits_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/contents/{+path}","compare_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/merges","archive_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/downloads","issues_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues{/number}","pulls_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls{/number}","milestones_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/milestones{/number}","notifications_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/labels{/name}","releases_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/releases{/id}","deployments_url":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/deployments","created_at":"2017-08-16T13:33:50Z","updated_at":"2017-08-22T07:35:47Z","pushed_at":"2017-09-01T10:53:48Z","git_url":"git://github.com/Tymoteuszauke/black-book-bot.git","ssh_url":"git@github.com:Tymoteuszauke/black-book-bot.git","clone_url":"https://github.com/Tymoteuszauke/black-book-bot.git","svn_url":"https://github.com/Tymoteuszauke/black-book-bot","homepage":null,"size":208,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/37"},"html":{"href":"https://github.com/Tymoteuszauke/black-book-bot/pull/37"},"issue":{"href":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues/37"},"comments":{"href":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/issues/37/comments"},"review_comments":{"href":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/37/comments"},"review_comment":{"href":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/pulls/37/commits"},"statuses":{"href":"https://api.github.com/repos/Tymoteuszauke/black-book-bot/statuses/9c4086f11c122bdd27cfec46c72f4b715fc4e46a"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"Devas"}}