GitHub PullRequestReviewCommentEvent at 2014-09-28 00:10:23
Repository: print-webapp
Actor: tylervz
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/comments/18126541","id":18126541,"diff_hunk":"@@ -0,0 +1,141 @@\n+from collections import namedtuple\n+import re\n+import requests\n+from requests_ntlm import HttpNtlmAuth\n+from bs4 import BeautifulSoup\n+\n+BASE_URL = 'https://print.calvin.edu/'\n+CLIENT_PATH = 'pwclient/'\n+RQM_PATH = 'pwrqm/'\n+AUTH_PATH = 'getuserid.asp'\n+PRINT_BUDGET_PATH = 'dispBudget.asp'\n+PRINT_QUEUE_PATH = 'dispObjects.asp'\n+\n+def get_uniflow_client(username, password):\n+    return UniflowClient(username, password)\n+\n+\n+class UniflowClient:\n+    def __init__(self, username, password):\n+        self._username = username\n+        self._password = password\n+        self._printStatusQueue = PrintStatus(RQM_PATH)\n+        self._printStatusBudget = PrintStatus(CLIENT_PATH)\n+\n+    def get_budget(self):\n+        self._printStatusBudget.sign_in(self._username, self._password)\n+        return self._printStatusBudget.get_budget()\n+\n+    def get_print_queue(self):\n+        self._printStatusQueue.sign_in(self._username, self._password)\n+        return self._printStatusQueue.get_queue()\n+\n+    #TODO: Make the function\n+    def get_print_history(self):\n+        return\n+\n+PrintJob = namedtuple('PrintJob',['name', 'pages', 'copies',\n+                                  'price', 'printer_name', 'date'])\n+\n+class PrintStatus:\n+    \"\"\"PrintStatus stores a session and a token.\"\"\"\n+    def __init__(self, path):\n+        \"\"\" path should either be CLIENT_PATH or RQM_PATH.\n+        \"\"\"\n+        if path != CLIENT_PATH and path != RQM_PATH:\n+            raise AttributeError(\"path must be either CLIENT_PATH or RQM_PATH\")\n+        self.path = path\n+        self._session = requests.Session()\n+\n+    def sign_in(self, username, password):\n+        domain = ''\n+        self._session.get(BASE_URL + self.path)\n+        self._session.auth = HttpNtlmAuth(domain + '\\\\' + username,\n+                                         password, self._session)\n+        post_data = {'theAction': 'ntlogin'}\n+        response = self._session.post(BASE_URL + self.path + AUTH_PATH,\n+                                     data=post_data)\n+        if response.status_code != requests.codes.ok:\n+            raise LoginError\n+        self.update_token(response.text)\n+\n+    def update_token(self, text):\n+        if self.path == CLIENT_PATH:\n+            match = re.search(r\"\\.c_updateToken\\(\\\"(.*)\\\"\\)\", text)\n+        elif self.path == RQM_PATH:\n+            match = re.search(r\"token=(.*)\\\";\", text)\n+        if match is not None:\n+            self._token = match.group(1)\n+            return\n+        raise ScrapingError\n+\n+    def get_budget(self):\n+        \"\"\"Returns the budget of the user.\"\"\"\n+        if self.path != CLIENT_PATH:\n+            raise AttributeError(\"PrintStatus instance has incorrect attribute 'path'\"\n+                                 + \"and therefore cannot call 'get_budget'\")\n+        query_parameters = {\n+            'mmtype': 'budget',\n+            'smtype': '',\n+            'token': self._token\n+        }\n+        \n+        response = self._session.get(BASE_URL + self.path + PRINT_BUDGET_PATH,\n+                                     params=query_parameters)\n+        if response.status_code != requests.codes.ok:\n+            raise NetworkError\n+        soup = BeautifulSoup(response.text, 'lxml')\n+        title = soup.find('title')\n+        if title is None:\n+            raise ScrapingError\n+        budget_tag = soup.find('font', class_= 'editHeadline')\n+        parent_tag = soup.find('font', class_= 'editHeadline').parent\n+        match = re.search(r\"Your current budget is:\", parent_tag.prettify())\n+        if match is None:\n+            raise ScrapingError\n+        budget = float(budget_tag.string)\n+        return budget\n+\n+    def get_queue(self):\n+        \"\"\"Returns a list of PrintJob objects to represent a user's print queue.\"\"\"\n+        if self.path != RQM_PATH:\n+            raise AttributeError(\"PrintStatus instance has incorrect attribute 'path' \\\n+                                and therefore cannot call 'get_queue'\")\n+        query_parameters = {\n+            'mmtype': 'login',\n+            'smtype': '',\n+            'token': self._token\n+        }\n+        \n+        response = self._session.get(BASE_URL + self.path + PRINT_QUEUE_PATH,\n+                                     params=query_parameters)\n+        if response.status_code != requests.codes.ok:\n+            raise NetworkError\n+        soup = BeautifulSoup(response.text, 'lxml')\n+        #TODO: Come up with a better way for checking for scraping errors\n+        title = soup.find('title')\n+        if title is None:\n+            raise ScrapingError\n+        print_job_tags = soup.select('#divMain tr td.Middle')\n+        print_jobs = []\n+        numberOfJobs = len(print_job_tags) / 7\n+        for i in range(numberOfJobs):\n+            j = i * 7\n+            name = unicode(print_job_tags[0 + j].string)","path":"src/printstatus.py","position":124,"original_position":124,"commit_id":"9895c7865d0190cc650f6dd3eb3a6cf5bf2e496d","original_commit_id":"9895c7865d0190cc650f6dd3eb3a6cf5bf2e496d","user":{"login":"tylervz","id":8753239,"avatar_url":"https://avatars.githubusercontent.com/u/8753239?v=2","gravatar_id":"","url":"https://api.github.com/users/tylervz","html_url":"https://github.com/tylervz","followers_url":"https://api.github.com/users/tylervz/followers","following_url":"https://api.github.com/users/tylervz/following{/other_user}","gists_url":"https://api.github.com/users/tylervz/gists{/gist_id}","starred_url":"https://api.github.com/users/tylervz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tylervz/subscriptions","organizations_url":"https://api.github.com/users/tylervz/orgs","repos_url":"https://api.github.com/users/tylervz/repos","events_url":"https://api.github.com/users/tylervz/events{/privacy}","received_events_url":"https://api.github.com/users/tylervz/received_events","type":"User","site_admin":false},"body":"Good call.","created_at":"2014-09-28T00:10:23Z","updated_at":"2014-09-28T00:10:23Z","html_url":"https://github.com/cs262a-fishsticks/print-webapp/pull/1#discussion_r18126541","pull_request_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/comments/18126541"},"html":{"href":"https://github.com/cs262a-fishsticks/print-webapp/pull/1#discussion_r18126541"},"pull_request":{"href":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/1","id":21816163,"html_url":"https://github.com/cs262a-fishsticks/print-webapp/pull/1","diff_url":"https://github.com/cs262a-fishsticks/print-webapp/pull/1.diff","patch_url":"https://github.com/cs262a-fishsticks/print-webapp/pull/1.patch","issue_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/issues/1","number":1,"state":"open","locked":false,"title":"Scrape to fetch print budget and queue data","user":{"login":"tylervz","id":8753239,"avatar_url":"https://avatars.githubusercontent.com/u/8753239?v=2","gravatar_id":"","url":"https://api.github.com/users/tylervz","html_url":"https://github.com/tylervz","followers_url":"https://api.github.com/users/tylervz/followers","following_url":"https://api.github.com/users/tylervz/following{/other_user}","gists_url":"https://api.github.com/users/tylervz/gists{/gist_id}","starred_url":"https://api.github.com/users/tylervz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tylervz/subscriptions","organizations_url":"https://api.github.com/users/tylervz/orgs","repos_url":"https://api.github.com/users/tylervz/repos","events_url":"https://api.github.com/users/tylervz/events{/privacy}","received_events_url":"https://api.github.com/users/tylervz/received_events","type":"User","site_admin":false},"body":"","created_at":"2014-09-25T22:04:49Z","updated_at":"2014-09-28T00:10:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0cf0ab077a95d6e8951f54c836f9003bf30584ad","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/1/commits","review_comments_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/1/comments","review_comment_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/comments/{number}","comments_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/issues/1/comments","statuses_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/statuses/9895c7865d0190cc650f6dd3eb3a6cf5bf2e496d","head":{"label":"tylervz:tyler","ref":"tyler","sha":"9895c7865d0190cc650f6dd3eb3a6cf5bf2e496d","user":{"login":"tylervz","id":8753239,"avatar_url":"https://avatars.githubusercontent.com/u/8753239?v=2","gravatar_id":"","url":"https://api.github.com/users/tylervz","html_url":"https://github.com/tylervz","followers_url":"https://api.github.com/users/tylervz/followers","following_url":"https://api.github.com/users/tylervz/following{/other_user}","gists_url":"https://api.github.com/users/tylervz/gists{/gist_id}","starred_url":"https://api.github.com/users/tylervz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tylervz/subscriptions","organizations_url":"https://api.github.com/users/tylervz/orgs","repos_url":"https://api.github.com/users/tylervz/repos","events_url":"https://api.github.com/users/tylervz/events{/privacy}","received_events_url":"https://api.github.com/users/tylervz/received_events","type":"User","site_admin":false},"repo":{"id":24476907,"name":"print-webapp","full_name":"tylervz/print-webapp","owner":{"login":"tylervz","id":8753239,"avatar_url":"https://avatars.githubusercontent.com/u/8753239?v=2","gravatar_id":"","url":"https://api.github.com/users/tylervz","html_url":"https://github.com/tylervz","followers_url":"https://api.github.com/users/tylervz/followers","following_url":"https://api.github.com/users/tylervz/following{/other_user}","gists_url":"https://api.github.com/users/tylervz/gists{/gist_id}","starred_url":"https://api.github.com/users/tylervz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tylervz/subscriptions","organizations_url":"https://api.github.com/users/tylervz/orgs","repos_url":"https://api.github.com/users/tylervz/repos","events_url":"https://api.github.com/users/tylervz/events{/privacy}","received_events_url":"https://api.github.com/users/tylervz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tylervz/print-webapp","description":"","fork":true,"url":"https://api.github.com/repos/tylervz/print-webapp","forks_url":"https://api.github.com/repos/tylervz/print-webapp/forks","keys_url":"https://api.github.com/repos/tylervz/print-webapp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tylervz/print-webapp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tylervz/print-webapp/teams","hooks_url":"https://api.github.com/repos/tylervz/print-webapp/hooks","issue_events_url":"https://api.github.com/repos/tylervz/print-webapp/issues/events{/number}","events_url":"https://api.github.com/repos/tylervz/print-webapp/events","assignees_url":"https://api.github.com/repos/tylervz/print-webapp/assignees{/user}","branches_url":"https://api.github.com/repos/tylervz/print-webapp/branches{/branch}","tags_url":"https://api.github.com/repos/tylervz/print-webapp/tags","blobs_url":"https://api.github.com/repos/tylervz/print-webapp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tylervz/print-webapp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tylervz/print-webapp/git/refs{/sha}","trees_url":"https://api.github.com/repos/tylervz/print-webapp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tylervz/print-webapp/statuses/{sha}","languages_url":"https://api.github.com/repos/tylervz/print-webapp/languages","stargazers_url":"https://api.github.com/repos/tylervz/print-webapp/stargazers","contributors_url":"https://api.github.com/repos/tylervz/print-webapp/contributors","subscribers_url":"https://api.github.com/repos/tylervz/print-webapp/subscribers","subscription_url":"https://api.github.com/repos/tylervz/print-webapp/subscription","commits_url":"https://api.github.com/repos/tylervz/print-webapp/commits{/sha}","git_commits_url":"https://api.github.com/repos/tylervz/print-webapp/git/commits{/sha}","comments_url":"https://api.github.com/repos/tylervz/print-webapp/comments{/number}","issue_comment_url":"https://api.github.com/repos/tylervz/print-webapp/issues/comments/{number}","contents_url":"https://api.github.com/repos/tylervz/print-webapp/contents/{+path}","compare_url":"https://api.github.com/repos/tylervz/print-webapp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tylervz/print-webapp/merges","archive_url":"https://api.github.com/repos/tylervz/print-webapp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tylervz/print-webapp/downloads","issues_url":"https://api.github.com/repos/tylervz/print-webapp/issues{/number}","pulls_url":"https://api.github.com/repos/tylervz/print-webapp/pulls{/number}","milestones_url":"https://api.github.com/repos/tylervz/print-webapp/milestones{/number}","notifications_url":"https://api.github.com/repos/tylervz/print-webapp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tylervz/print-webapp/labels{/name}","releases_url":"https://api.github.com/repos/tylervz/print-webapp/releases{/id}","created_at":"2014-09-25T22:02:38Z","updated_at":"2014-09-18T03:04:37Z","pushed_at":"2014-09-27T20:17:24Z","git_url":"git://github.com/tylervz/print-webapp.git","ssh_url":"git@github.com:tylervz/print-webapp.git","clone_url":"https://github.com/tylervz/print-webapp.git","svn_url":"https://github.com/tylervz/print-webapp","homepage":null,"size":269,"stargazers_count":0,"watchers_count":0,"language":null,"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":"cs262a-fishsticks:master","ref":"master","sha":"3755252ed2d38208ef43664fe146595823278a84","user":{"login":"cs262a-fishsticks","id":8753800,"avatar_url":"https://avatars.githubusercontent.com/u/8753800?v=2","gravatar_id":"","url":"https://api.github.com/users/cs262a-fishsticks","html_url":"https://github.com/cs262a-fishsticks","followers_url":"https://api.github.com/users/cs262a-fishsticks/followers","following_url":"https://api.github.com/users/cs262a-fishsticks/following{/other_user}","gists_url":"https://api.github.com/users/cs262a-fishsticks/gists{/gist_id}","starred_url":"https://api.github.com/users/cs262a-fishsticks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cs262a-fishsticks/subscriptions","organizations_url":"https://api.github.com/users/cs262a-fishsticks/orgs","repos_url":"https://api.github.com/users/cs262a-fishsticks/repos","events_url":"https://api.github.com/users/cs262a-fishsticks/events{/privacy}","received_events_url":"https://api.github.com/users/cs262a-fishsticks/received_events","type":"Organization","site_admin":false},"repo":{"id":24171509,"name":"print-webapp","full_name":"cs262a-fishsticks/print-webapp","owner":{"login":"cs262a-fishsticks","id":8753800,"avatar_url":"https://avatars.githubusercontent.com/u/8753800?v=2","gravatar_id":"","url":"https://api.github.com/users/cs262a-fishsticks","html_url":"https://github.com/cs262a-fishsticks","followers_url":"https://api.github.com/users/cs262a-fishsticks/followers","following_url":"https://api.github.com/users/cs262a-fishsticks/following{/other_user}","gists_url":"https://api.github.com/users/cs262a-fishsticks/gists{/gist_id}","starred_url":"https://api.github.com/users/cs262a-fishsticks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cs262a-fishsticks/subscriptions","organizations_url":"https://api.github.com/users/cs262a-fishsticks/orgs","repos_url":"https://api.github.com/users/cs262a-fishsticks/repos","events_url":"https://api.github.com/users/cs262a-fishsticks/events{/privacy}","received_events_url":"https://api.github.com/users/cs262a-fishsticks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cs262a-fishsticks/print-webapp","description":"","fork":false,"url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp","forks_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/forks","keys_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/teams","hooks_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/hooks","issue_events_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/issues/events{/number}","events_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/events","assignees_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/assignees{/user}","branches_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/branches{/branch}","tags_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/tags","blobs_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/git/refs{/sha}","trees_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/statuses/{sha}","languages_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/languages","stargazers_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/stargazers","contributors_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/contributors","subscribers_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/subscribers","subscription_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/subscription","commits_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/commits{/sha}","git_commits_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/git/commits{/sha}","comments_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/comments{/number}","issue_comment_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/issues/comments/{number}","contents_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/contents/{+path}","compare_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/merges","archive_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/downloads","issues_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/issues{/number}","pulls_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls{/number}","milestones_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/milestones{/number}","notifications_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/labels{/name}","releases_url":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/releases{/id}","created_at":"2014-09-18T02:51:21Z","updated_at":"2014-09-18T03:04:37Z","pushed_at":"2014-09-27T18:59:28Z","git_url":"git://github.com/cs262a-fishsticks/print-webapp.git","ssh_url":"git@github.com:cs262a-fishsticks/print-webapp.git","clone_url":"https://github.com/cs262a-fishsticks/print-webapp.git","svn_url":"https://github.com/cs262a-fishsticks/print-webapp","homepage":null,"size":269,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/1"},"html":{"href":"https://github.com/cs262a-fishsticks/print-webapp/pull/1"},"issue":{"href":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/issues/1"},"comments":{"href":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/cs262a-fishsticks/print-webapp/statuses/9895c7865d0190cc650f6dd3eb3a6cf5bf2e496d"}}}}