{"action":"created","comment":{"url":"https://api.github.com/repos/aspc/mainsite/pulls/comments/77767808","id":77767808,"diff_hunk":"@@ -50,6 +57,46 @@ def save(self, *args, **kwargs):\n         if created and not self.is_recoop:\n             new_activity.send(sender=self, category=\"sagelist\", date=self.posted)\n \n+    def update_amazon_info(self):\n+        if not self.isbn:\n+            return\n+        products = amazon.search_n(1,Keywords=self.isbn.replace('-',''), SearchIndex='Books')\n+        if not len(products):\n+            return\n+        amazon_info = {}\n+        amazon_info['price'] = products[0].price_and_currency[0]\n+        amazon_info['image_url'] = products[0].large_image_url\n+        amazon_info['url'] = products[0].offer_url\n+        amazon_info['description'] = products[0].editorial_review\n+        self.title = products[0].title\n+        self.authors = products[0].author\n+        self.edition = str(products[0].edition)\n+        self.amazon_info = json.dumps(amazon_info)\n+        self.save()\n+\n+    def get_amazon_attribute(self, attribute):\n+        if not self.amazon_info:\n+            return None\n+        amazon_info = json.loads(self.amazon_info)\n+        return amazon_info.get(attribute)\n+\n+    def amazon_price(self):\n+        return self.get_amazon_attribute('price')","path":"aspc/sagelist/models.py","position":55,"original_position":50,"commit_id":"5b628451a9a65631633a09c228b03088ba2c63a5","original_commit_id":"07f21a7dd429c328cd896cff57527edc6924a153","user":{"login":"KentShikama","id":6329898,"avatar_url":"https://avatars.githubusercontent.com/u/6329898?v=3","gravatar_id":"","url":"https://api.github.com/users/KentShikama","html_url":"https://github.com/KentShikama","followers_url":"https://api.github.com/users/KentShikama/followers","following_url":"https://api.github.com/users/KentShikama/following{/other_user}","gists_url":"https://api.github.com/users/KentShikama/gists{/gist_id}","starred_url":"https://api.github.com/users/KentShikama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KentShikama/subscriptions","organizations_url":"https://api.github.com/users/KentShikama/orgs","repos_url":"https://api.github.com/users/KentShikama/repos","events_url":"https://api.github.com/users/KentShikama/events{/privacy}","received_events_url":"https://api.github.com/users/KentShikama/received_events","type":"User","site_admin":false},"body":"Got it. Just checking since you answered \"no\" to \"Is it a new book sold by Amazon though?\". I think stating \"$14 cheaper than a _new_ version on Amazon\" is fair.","created_at":"2016-09-07T06:49:38Z","updated_at":"2016-09-07T06:49:38Z","html_url":"https://github.com/aspc/mainsite/pull/121#discussion_r77767808","pull_request_url":"https://api.github.com/repos/aspc/mainsite/pulls/121","_links":{"self":{"href":"https://api.github.com/repos/aspc/mainsite/pulls/comments/77767808"},"html":{"href":"https://github.com/aspc/mainsite/pull/121#discussion_r77767808"},"pull_request":{"href":"https://api.github.com/repos/aspc/mainsite/pulls/121"}}},"pull_request":{"url":"https://api.github.com/repos/aspc/mainsite/pulls/121","id":84160250,"html_url":"https://github.com/aspc/mainsite/pull/121","diff_url":"https://github.com/aspc/mainsite/pull/121.diff","patch_url":"https://github.com/aspc/mainsite/pull/121.patch","issue_url":"https://api.github.com/repos/aspc/mainsite/issues/121","number":121,"state":"open","locked":false,"title":"Use Amazon ItemSearch API to enrich and regularize our BookSale data","user":{"login":"ZiqiXiong","id":7268310,"avatar_url":"https://avatars.githubusercontent.com/u/7268310?v=3","gravatar_id":"","url":"https://api.github.com/users/ZiqiXiong","html_url":"https://github.com/ZiqiXiong","followers_url":"https://api.github.com/users/ZiqiXiong/followers","following_url":"https://api.github.com/users/ZiqiXiong/following{/other_user}","gists_url":"https://api.github.com/users/ZiqiXiong/gists{/gist_id}","starred_url":"https://api.github.com/users/ZiqiXiong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZiqiXiong/subscriptions","organizations_url":"https://api.github.com/users/ZiqiXiong/orgs","repos_url":"https://api.github.com/users/ZiqiXiong/repos","events_url":"https://api.github.com/users/ZiqiXiong/events{/privacy}","received_events_url":"https://api.github.com/users/ZiqiXiong/received_events","type":"User","site_admin":false},"body":"This PR aims to use Amazon ItemSearch API to solve two problems that the SageBook app has for a while:\r\n*  The irregularity of BookSale attributes: Almost all the attributes of a BookSale object is input by the seller and lack consistency. An edition of a book can be \"1st edition\", \"1\", \"first edition\", \"2016 edition\", etc. Same problem with the title and the authors of the book. It makes it hard for us to organize the book items and provides useful queries based on those attributes.\r\n* The deficiency in BookSale attributes: Right now we keep the minimal amount of information of each BookSale. This made sense since the more information we wanted from the BookSale object, the more difficult it is for user to submit their listing. However, this makes SageBook only suitable for people who know who they are going to buy, in this case, textbooks, and excludes undecided book lovers who don't have a specific book in mind but just want to browser (and consider buying) some cheap books available on our site. \r\n\r\nThe two problems can be both solved by utilizing Amazon''s ItemSearch API:\r\n\r\n* It doesn't matter if user puts in the correct book title, authors or edition. As long as the ISBN number is correct, we can use it to look up the book on Amazon, fetches its title, authors, and edition, and use them to overwrite user's input. This guarantees that all the listings of the same book on SageBook will have the same title, authors, and edition.\r\n* Amazon API also gives us the price, cover image and editorial review of the book. We can use this information to better inform our users whether to buy the book.\r\n\r\nBelow is an example how you can list the book playfully and how the sale will look to other.\r\n\r\n<img width=\"991\" alt=\"screenshot 2016-09-06 10 05 51\" src=\"https://cloud.githubusercontent.com/assets/7268310/18283336/92612abc-7419-11e6-8e4e-07363d0b3fb3.png\">\r\n<img width=\"993\" alt=\"screenshot 2016-09-06 10 06 01\" src=\"https://cloud.githubusercontent.com/assets/7268310/18283335/925fc69a-7419-11e6-8253-967e4be5bf6e.png\">\r\n","created_at":"2016-09-06T17:08:20Z","updated_at":"2016-09-07T06:49:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eab99f75199a3d740a388019fcc4de06cd0b643f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/aspc/mainsite/pulls/121/commits","review_comments_url":"https://api.github.com/repos/aspc/mainsite/pulls/121/comments","review_comment_url":"https://api.github.com/repos/aspc/mainsite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspc/mainsite/issues/121/comments","statuses_url":"https://api.github.com/repos/aspc/mainsite/statuses/5b628451a9a65631633a09c228b03088ba2c63a5","head":{"label":"aspc:amazon_api","ref":"amazon_api","sha":"5b628451a9a65631633a09c228b03088ba2c63a5","user":{"login":"aspc","id":1634479,"avatar_url":"https://avatars.githubusercontent.com/u/1634479?v=3","gravatar_id":"","url":"https://api.github.com/users/aspc","html_url":"https://github.com/aspc","followers_url":"https://api.github.com/users/aspc/followers","following_url":"https://api.github.com/users/aspc/following{/other_user}","gists_url":"https://api.github.com/users/aspc/gists{/gist_id}","starred_url":"https://api.github.com/users/aspc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspc/subscriptions","organizations_url":"https://api.github.com/users/aspc/orgs","repos_url":"https://api.github.com/users/aspc/repos","events_url":"https://api.github.com/users/aspc/events{/privacy}","received_events_url":"https://api.github.com/users/aspc/received_events","type":"Organization","site_admin":false},"repo":{"id":3998083,"name":"mainsite","full_name":"aspc/mainsite","owner":{"login":"aspc","id":1634479,"avatar_url":"https://avatars.githubusercontent.com/u/1634479?v=3","gravatar_id":"","url":"https://api.github.com/users/aspc","html_url":"https://github.com/aspc","followers_url":"https://api.github.com/users/aspc/followers","following_url":"https://api.github.com/users/aspc/following{/other_user}","gists_url":"https://api.github.com/users/aspc/gists{/gist_id}","starred_url":"https://api.github.com/users/aspc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspc/subscriptions","organizations_url":"https://api.github.com/users/aspc/orgs","repos_url":"https://api.github.com/users/aspc/repos","events_url":"https://api.github.com/users/aspc/events{/privacy}","received_events_url":"https://api.github.com/users/aspc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspc/mainsite","description":"The code powering the ASPC main site (including menus, course scheduler, sagebooks, and housing reviews).","fork":false,"url":"https://api.github.com/repos/aspc/mainsite","forks_url":"https://api.github.com/repos/aspc/mainsite/forks","keys_url":"https://api.github.com/repos/aspc/mainsite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspc/mainsite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspc/mainsite/teams","hooks_url":"https://api.github.com/repos/aspc/mainsite/hooks","issue_events_url":"https://api.github.com/repos/aspc/mainsite/issues/events{/number}","events_url":"https://api.github.com/repos/aspc/mainsite/events","assignees_url":"https://api.github.com/repos/aspc/mainsite/assignees{/user}","branches_url":"https://api.github.com/repos/aspc/mainsite/branches{/branch}","tags_url":"https://api.github.com/repos/aspc/mainsite/tags","blobs_url":"https://api.github.com/repos/aspc/mainsite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspc/mainsite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspc/mainsite/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspc/mainsite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspc/mainsite/statuses/{sha}","languages_url":"https://api.github.com/repos/aspc/mainsite/languages","stargazers_url":"https://api.github.com/repos/aspc/mainsite/stargazers","contributors_url":"https://api.github.com/repos/aspc/mainsite/contributors","subscribers_url":"https://api.github.com/repos/aspc/mainsite/subscribers","subscription_url":"https://api.github.com/repos/aspc/mainsite/subscription","commits_url":"https://api.github.com/repos/aspc/mainsite/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspc/mainsite/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspc/mainsite/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspc/mainsite/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspc/mainsite/contents/{+path}","compare_url":"https://api.github.com/repos/aspc/mainsite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspc/mainsite/merges","archive_url":"https://api.github.com/repos/aspc/mainsite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspc/mainsite/downloads","issues_url":"https://api.github.com/repos/aspc/mainsite/issues{/number}","pulls_url":"https://api.github.com/repos/aspc/mainsite/pulls{/number}","milestones_url":"https://api.github.com/repos/aspc/mainsite/milestones{/number}","notifications_url":"https://api.github.com/repos/aspc/mainsite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspc/mainsite/labels{/name}","releases_url":"https://api.github.com/repos/aspc/mainsite/releases{/id}","deployments_url":"https://api.github.com/repos/aspc/mainsite/deployments","created_at":"2012-04-11T20:43:21Z","updated_at":"2016-08-26T01:31:29Z","pushed_at":"2016-09-07T06:26:41Z","git_url":"git://github.com/aspc/mainsite.git","ssh_url":"git@github.com:aspc/mainsite.git","clone_url":"https://github.com/aspc/mainsite.git","svn_url":"https://github.com/aspc/mainsite","homepage":"https://aspc.pomona.edu/","size":7995,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":31,"forks":8,"open_issues":31,"watchers":6,"default_branch":"master"}},"base":{"label":"aspc:master","ref":"master","sha":"0ec3622a60a18259315a012bd5289b72db9361e3","user":{"login":"aspc","id":1634479,"avatar_url":"https://avatars.githubusercontent.com/u/1634479?v=3","gravatar_id":"","url":"https://api.github.com/users/aspc","html_url":"https://github.com/aspc","followers_url":"https://api.github.com/users/aspc/followers","following_url":"https://api.github.com/users/aspc/following{/other_user}","gists_url":"https://api.github.com/users/aspc/gists{/gist_id}","starred_url":"https://api.github.com/users/aspc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspc/subscriptions","organizations_url":"https://api.github.com/users/aspc/orgs","repos_url":"https://api.github.com/users/aspc/repos","events_url":"https://api.github.com/users/aspc/events{/privacy}","received_events_url":"https://api.github.com/users/aspc/received_events","type":"Organization","site_admin":false},"repo":{"id":3998083,"name":"mainsite","full_name":"aspc/mainsite","owner":{"login":"aspc","id":1634479,"avatar_url":"https://avatars.githubusercontent.com/u/1634479?v=3","gravatar_id":"","url":"https://api.github.com/users/aspc","html_url":"https://github.com/aspc","followers_url":"https://api.github.com/users/aspc/followers","following_url":"https://api.github.com/users/aspc/following{/other_user}","gists_url":"https://api.github.com/users/aspc/gists{/gist_id}","starred_url":"https://api.github.com/users/aspc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspc/subscriptions","organizations_url":"https://api.github.com/users/aspc/orgs","repos_url":"https://api.github.com/users/aspc/repos","events_url":"https://api.github.com/users/aspc/events{/privacy}","received_events_url":"https://api.github.com/users/aspc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspc/mainsite","description":"The code powering the ASPC main site (including menus, course scheduler, sagebooks, and housing reviews).","fork":false,"url":"https://api.github.com/repos/aspc/mainsite","forks_url":"https://api.github.com/repos/aspc/mainsite/forks","keys_url":"https://api.github.com/repos/aspc/mainsite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspc/mainsite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspc/mainsite/teams","hooks_url":"https://api.github.com/repos/aspc/mainsite/hooks","issue_events_url":"https://api.github.com/repos/aspc/mainsite/issues/events{/number}","events_url":"https://api.github.com/repos/aspc/mainsite/events","assignees_url":"https://api.github.com/repos/aspc/mainsite/assignees{/user}","branches_url":"https://api.github.com/repos/aspc/mainsite/branches{/branch}","tags_url":"https://api.github.com/repos/aspc/mainsite/tags","blobs_url":"https://api.github.com/repos/aspc/mainsite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspc/mainsite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspc/mainsite/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspc/mainsite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspc/mainsite/statuses/{sha}","languages_url":"https://api.github.com/repos/aspc/mainsite/languages","stargazers_url":"https://api.github.com/repos/aspc/mainsite/stargazers","contributors_url":"https://api.github.com/repos/aspc/mainsite/contributors","subscribers_url":"https://api.github.com/repos/aspc/mainsite/subscribers","subscription_url":"https://api.github.com/repos/aspc/mainsite/subscription","commits_url":"https://api.github.com/repos/aspc/mainsite/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspc/mainsite/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspc/mainsite/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspc/mainsite/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspc/mainsite/contents/{+path}","compare_url":"https://api.github.com/repos/aspc/mainsite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspc/mainsite/merges","archive_url":"https://api.github.com/repos/aspc/mainsite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspc/mainsite/downloads","issues_url":"https://api.github.com/repos/aspc/mainsite/issues{/number}","pulls_url":"https://api.github.com/repos/aspc/mainsite/pulls{/number}","milestones_url":"https://api.github.com/repos/aspc/mainsite/milestones{/number}","notifications_url":"https://api.github.com/repos/aspc/mainsite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspc/mainsite/labels{/name}","releases_url":"https://api.github.com/repos/aspc/mainsite/releases{/id}","deployments_url":"https://api.github.com/repos/aspc/mainsite/deployments","created_at":"2012-04-11T20:43:21Z","updated_at":"2016-08-26T01:31:29Z","pushed_at":"2016-09-07T06:26:41Z","git_url":"git://github.com/aspc/mainsite.git","ssh_url":"git@github.com:aspc/mainsite.git","clone_url":"https://github.com/aspc/mainsite.git","svn_url":"https://github.com/aspc/mainsite","homepage":"https://aspc.pomona.edu/","size":7995,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":31,"forks":8,"open_issues":31,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/aspc/mainsite/pulls/121"},"html":{"href":"https://github.com/aspc/mainsite/pull/121"},"issue":{"href":"https://api.github.com/repos/aspc/mainsite/issues/121"},"comments":{"href":"https://api.github.com/repos/aspc/mainsite/issues/121/comments"},"review_comments":{"href":"https://api.github.com/repos/aspc/mainsite/pulls/121/comments"},"review_comment":{"href":"https://api.github.com/repos/aspc/mainsite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspc/mainsite/pulls/121/commits"},"statuses":{"href":"https://api.github.com/repos/aspc/mainsite/statuses/5b628451a9a65631633a09c228b03088ba2c63a5"}}}}
{"actor":{"display_login":"KentShikama"}}