{"action":"created","comment":{"url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/comments/60488904","id":60488904,"diff_hunk":"@@ -0,0 +1,107 @@\n+import cheerio from 'cheerio';\n+import rp from 'request-promise';\n+\n+if (Meteor.isServer) {\n+    Meteor.methods({\n+        request: (url) => {\n+            return rp(url)\n+                    .then((body) => {\n+                        return body;\n+                    })\n+                    .catch((err) => {\n+                        throw new Error('error request');\n+                    });\n+        }\n+    });\n+}\n+\n+class ParserClass {\n+    constructor() {\n+        this.shops = {\n+            'www.eda.by': {\n+                title:  '.dishinfo > h2',\n+                weight: '.dishinfo > span',\n+                price:  '.dishinfo > b',\n+                descr:  '.summary'\n+            },\n+            'www.wok.by': {\n+                title:  'h1.productTitle',\n+                weight: 'span.productIntro',\n+                price:  'span.price',\n+                descr:  '.controls .checkbox'\n+            }\n+        };\n+    }\n+\n+    /**\n+     * Проверяет корректность url\n+     *\n+     * @param {string} url адрес страницы\n+     * @returns {bool} Валиден?\n+     */\n+    validUrl(url) {\n+        // http://stackoverflow.com/questions/1410311/regular-expression-for-url-validation-in-javascript\n+        return url.match(/(ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?/);\n+    }\n+\n+    /**\n+     * Проверяет знает ли он такой url\n+     *\n+     * @param {string} url адрес страницы\n+     * @returns {bool} Валиден?\n+     */\n+    approveFromUrl(url) {\n+        return this.getShop(url) in this.shops;\n+    }\n+\n+    /**\n+     * Ищет хеш магазина из url\n+     *\n+     * @param {string} url адрес страницы\n+     * @returns {string} хеш магазина\n+     */\n+    getShop(url) {\n+        let link = document.createElement('a');\n+        link.href = url;\n+        return link.hostname;\n+    }\n+\n+    /**\n+     * Главный метод,\n+     * -> принимает url\n+     * проверяет его корректность\n+     * проверяет может ли заапрувить его\n+     * выбирает магазин\n+     * подбирает нужный парсинг-объект из выбранного магазина\n+     * делает запрос на сервер\n+     * выбирает нужные параметры\n+     * <- возвращает объект Item\n+     * @param {string} url адрес страницы\n+     * @returns {Object} выбранный товар\n+     */\n+    parse(url) {\n+        if (this.validUrl(url) && this.approveFromUrl(url)) {\n+            let shopkey = this.getShop(url);\n+            let objparse = this.shops[shopkey];\n+\n+            Meteor.call('request', url, function(error, result) {\n+                $ = cheerio.load(result);","path":"lib/parser.js","position":88,"original_position":88,"commit_id":"b21e2fd14402ae2f620b7a4ef88c62d139b625b5","original_commit_id":"b21e2fd14402ae2f620b7a4ef88c62d139b625b5","user":{"login":"denisbalyko","id":638190,"avatar_url":"https://avatars.githubusercontent.com/u/638190?v=3","gravatar_id":"","url":"https://api.github.com/users/denisbalyko","html_url":"https://github.com/denisbalyko","followers_url":"https://api.github.com/users/denisbalyko/followers","following_url":"https://api.github.com/users/denisbalyko/following{/other_user}","gists_url":"https://api.github.com/users/denisbalyko/gists{/gist_id}","starred_url":"https://api.github.com/users/denisbalyko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denisbalyko/subscriptions","organizations_url":"https://api.github.com/users/denisbalyko/orgs","repos_url":"https://api.github.com/users/denisbalyko/repos","events_url":"https://api.github.com/users/denisbalyko/events{/privacy}","received_events_url":"https://api.github.com/users/denisbalyko/received_events","type":"User","site_admin":false},"body":"Какой из? Про cheerio - он в import.","created_at":"2016-04-20T21:14:05Z","updated_at":"2016-04-20T21:14:05Z","html_url":"https://github.com/yandex-shri-minsk-2016/team-force/pull/42#discussion_r60488904","pull_request_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/42","_links":{"self":{"href":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/comments/60488904"},"html":{"href":"https://github.com/yandex-shri-minsk-2016/team-force/pull/42#discussion_r60488904"},"pull_request":{"href":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/42"}}},"pull_request":{"url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/42","id":67246609,"html_url":"https://github.com/yandex-shri-minsk-2016/team-force/pull/42","diff_url":"https://github.com/yandex-shri-minsk-2016/team-force/pull/42.diff","patch_url":"https://github.com/yandex-shri-minsk-2016/team-force/pull/42.patch","issue_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues/42","number":42,"state":"open","locked":false,"title":"Feature/parser","user":{"login":"denisbalyko","id":638190,"avatar_url":"https://avatars.githubusercontent.com/u/638190?v=3","gravatar_id":"","url":"https://api.github.com/users/denisbalyko","html_url":"https://github.com/denisbalyko","followers_url":"https://api.github.com/users/denisbalyko/followers","following_url":"https://api.github.com/users/denisbalyko/following{/other_user}","gists_url":"https://api.github.com/users/denisbalyko/gists{/gist_id}","starred_url":"https://api.github.com/users/denisbalyko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denisbalyko/subscriptions","organizations_url":"https://api.github.com/users/denisbalyko/orgs","repos_url":"https://api.github.com/users/denisbalyko/repos","events_url":"https://api.github.com/users/denisbalyko/events{/privacy}","received_events_url":"https://api.github.com/users/denisbalyko/received_events","type":"User","site_admin":false},"body":"Есть небольшие проблемы с кодировкой, но это решится если примем общую концепцию.\n\nЗазываю всех заревьювить этот код.","created_at":"2016-04-20T19:44:44Z","updated_at":"2016-04-20T21:14:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"288777637dfe070fd40f9d4a15bec88465966481","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/42/commits","review_comments_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/42/comments","review_comment_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/comments{/number}","comments_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues/42/comments","statuses_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/statuses/b21e2fd14402ae2f620b7a4ef88c62d139b625b5","head":{"label":"yandex-shri-minsk-2016:feature/parser","ref":"feature/parser","sha":"b21e2fd14402ae2f620b7a4ef88c62d139b625b5","user":{"login":"yandex-shri-minsk-2016","id":17139900,"avatar_url":"https://avatars.githubusercontent.com/u/17139900?v=3","gravatar_id":"","url":"https://api.github.com/users/yandex-shri-minsk-2016","html_url":"https://github.com/yandex-shri-minsk-2016","followers_url":"https://api.github.com/users/yandex-shri-minsk-2016/followers","following_url":"https://api.github.com/users/yandex-shri-minsk-2016/following{/other_user}","gists_url":"https://api.github.com/users/yandex-shri-minsk-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/yandex-shri-minsk-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yandex-shri-minsk-2016/subscriptions","organizations_url":"https://api.github.com/users/yandex-shri-minsk-2016/orgs","repos_url":"https://api.github.com/users/yandex-shri-minsk-2016/repos","events_url":"https://api.github.com/users/yandex-shri-minsk-2016/events{/privacy}","received_events_url":"https://api.github.com/users/yandex-shri-minsk-2016/received_events","type":"Organization","site_admin":false},"repo":{"id":55834284,"name":"team-force","full_name":"yandex-shri-minsk-2016/team-force","owner":{"login":"yandex-shri-minsk-2016","id":17139900,"avatar_url":"https://avatars.githubusercontent.com/u/17139900?v=3","gravatar_id":"","url":"https://api.github.com/users/yandex-shri-minsk-2016","html_url":"https://github.com/yandex-shri-minsk-2016","followers_url":"https://api.github.com/users/yandex-shri-minsk-2016/followers","following_url":"https://api.github.com/users/yandex-shri-minsk-2016/following{/other_user}","gists_url":"https://api.github.com/users/yandex-shri-minsk-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/yandex-shri-minsk-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yandex-shri-minsk-2016/subscriptions","organizations_url":"https://api.github.com/users/yandex-shri-minsk-2016/orgs","repos_url":"https://api.github.com/users/yandex-shri-minsk-2016/repos","events_url":"https://api.github.com/users/yandex-shri-minsk-2016/events{/privacy}","received_events_url":"https://api.github.com/users/yandex-shri-minsk-2016/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yandex-shri-minsk-2016/team-force","description":"","fork":false,"url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force","forks_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/forks","keys_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/teams","hooks_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/hooks","issue_events_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues/events{/number}","events_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/events","assignees_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/assignees{/user}","branches_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/branches{/branch}","tags_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/tags","blobs_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/refs{/sha}","trees_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/statuses/{sha}","languages_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/languages","stargazers_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/stargazers","contributors_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/contributors","subscribers_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/subscribers","subscription_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/subscription","commits_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/commits{/sha}","git_commits_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/commits{/sha}","comments_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/comments{/number}","issue_comment_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues/comments{/number}","contents_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/contents/{+path}","compare_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/merges","archive_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/downloads","issues_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues{/number}","pulls_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls{/number}","milestones_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/milestones{/number}","notifications_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/labels{/name}","releases_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/releases{/id}","deployments_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/deployments","created_at":"2016-04-09T08:43:52Z","updated_at":"2016-04-09T16:14:29Z","pushed_at":"2016-04-20T20:58:59Z","git_url":"git://github.com/yandex-shri-minsk-2016/team-force.git","ssh_url":"git@github.com:yandex-shri-minsk-2016/team-force.git","clone_url":"https://github.com/yandex-shri-minsk-2016/team-force.git","svn_url":"https://github.com/yandex-shri-minsk-2016/team-force","homepage":null,"size":104,"stargazers_count":5,"watchers_count":5,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":12,"forks":0,"open_issues":12,"watchers":5,"default_branch":"master"}},"base":{"label":"yandex-shri-minsk-2016:dev","ref":"dev","sha":"b02dab0205f6590175d0eb7df3a7864338f14023","user":{"login":"yandex-shri-minsk-2016","id":17139900,"avatar_url":"https://avatars.githubusercontent.com/u/17139900?v=3","gravatar_id":"","url":"https://api.github.com/users/yandex-shri-minsk-2016","html_url":"https://github.com/yandex-shri-minsk-2016","followers_url":"https://api.github.com/users/yandex-shri-minsk-2016/followers","following_url":"https://api.github.com/users/yandex-shri-minsk-2016/following{/other_user}","gists_url":"https://api.github.com/users/yandex-shri-minsk-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/yandex-shri-minsk-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yandex-shri-minsk-2016/subscriptions","organizations_url":"https://api.github.com/users/yandex-shri-minsk-2016/orgs","repos_url":"https://api.github.com/users/yandex-shri-minsk-2016/repos","events_url":"https://api.github.com/users/yandex-shri-minsk-2016/events{/privacy}","received_events_url":"https://api.github.com/users/yandex-shri-minsk-2016/received_events","type":"Organization","site_admin":false},"repo":{"id":55834284,"name":"team-force","full_name":"yandex-shri-minsk-2016/team-force","owner":{"login":"yandex-shri-minsk-2016","id":17139900,"avatar_url":"https://avatars.githubusercontent.com/u/17139900?v=3","gravatar_id":"","url":"https://api.github.com/users/yandex-shri-minsk-2016","html_url":"https://github.com/yandex-shri-minsk-2016","followers_url":"https://api.github.com/users/yandex-shri-minsk-2016/followers","following_url":"https://api.github.com/users/yandex-shri-minsk-2016/following{/other_user}","gists_url":"https://api.github.com/users/yandex-shri-minsk-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/yandex-shri-minsk-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yandex-shri-minsk-2016/subscriptions","organizations_url":"https://api.github.com/users/yandex-shri-minsk-2016/orgs","repos_url":"https://api.github.com/users/yandex-shri-minsk-2016/repos","events_url":"https://api.github.com/users/yandex-shri-minsk-2016/events{/privacy}","received_events_url":"https://api.github.com/users/yandex-shri-minsk-2016/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yandex-shri-minsk-2016/team-force","description":"","fork":false,"url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force","forks_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/forks","keys_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/teams","hooks_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/hooks","issue_events_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues/events{/number}","events_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/events","assignees_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/assignees{/user}","branches_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/branches{/branch}","tags_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/tags","blobs_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/refs{/sha}","trees_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/statuses/{sha}","languages_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/languages","stargazers_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/stargazers","contributors_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/contributors","subscribers_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/subscribers","subscription_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/subscription","commits_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/commits{/sha}","git_commits_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/git/commits{/sha}","comments_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/comments{/number}","issue_comment_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues/comments{/number}","contents_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/contents/{+path}","compare_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/merges","archive_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/downloads","issues_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues{/number}","pulls_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls{/number}","milestones_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/milestones{/number}","notifications_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/labels{/name}","releases_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/releases{/id}","deployments_url":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/deployments","created_at":"2016-04-09T08:43:52Z","updated_at":"2016-04-09T16:14:29Z","pushed_at":"2016-04-20T20:58:59Z","git_url":"git://github.com/yandex-shri-minsk-2016/team-force.git","ssh_url":"git@github.com:yandex-shri-minsk-2016/team-force.git","clone_url":"https://github.com/yandex-shri-minsk-2016/team-force.git","svn_url":"https://github.com/yandex-shri-minsk-2016/team-force","homepage":null,"size":104,"stargazers_count":5,"watchers_count":5,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":12,"forks":0,"open_issues":12,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/42"},"html":{"href":"https://github.com/yandex-shri-minsk-2016/team-force/pull/42"},"issue":{"href":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues/42"},"comments":{"href":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/issues/42/comments"},"review_comments":{"href":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/42/comments"},"review_comment":{"href":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/pulls/42/commits"},"statuses":{"href":"https://api.github.com/repos/yandex-shri-minsk-2016/team-force/statuses/b21e2fd14402ae2f620b7a4ef88c62d139b625b5"}}}}