{"action":"created","comment":{"url":"https://api.github.com/repos/tejal29/grepg/pulls/comments/70757670","id":70757670,"diff_hunk":"@@ -0,0 +1,76 @@\n+from __future__ import print_function\n+\n+from util.utils import since_time_in_words, print_util\n+from lib.cheat_sheets_model import CheatSheetsCache\n+from lib.grepg_api import GrepgAPI\n+\n+from twitter.common import log\n+\n+\n+class CommandError(Exception):\n+  def __init__(self, mesg):\n+    super(CommandError, self).__init__(mesg)\n+\n+\n+class GrepgClient(object):\n+  def __init__(self, username, topic, search_term, colorize, force, ttl, base_url=None, access_token=None, ):\n+    self.user_name = username\n+    self.topic = topic\n+    self.search_term = search_term\n+    self.force = force\n+    self.colorize = colorize\n+    self.ttl =ttl\n+    self.api = GrepgAPI.get_grepg_api(base_url, access_token)\n+\n+  def _get_user_topics(self):\n+    with CheatSheetsCache(self.ttl) as cs:\n+      if self.force or not cs.has_valid_user_cheat_sheets(self.user_name):\n+        log.debug('Fetching user cheats from server')\n+        user_sheet = self.api.sheets(self.user_name)\n+        cs.add_or_update_sheet(self.user_name, user_sheet)\n+      return cs.get_user_topics(self.user_name)\n+\n+  def get_user_topics(self, print_header=True):\n+    (since_timestamp, topic_map) = self._get_user_topics()\n+    if print_header:\n+      print_util(\"User: {0}, Last Fetched: {1} ago\".format(self.user_name, since_time_in_words(since_timestamp)), 'green', self.colorize)\n+    print_util(\"Available Topics =>\", 'green', self.colorize)\n+    topics = [topic.topic_name for topic in topic_map.values()]\n+    print_util('\\t'.join(topics), 'blue', self.colorize)\n+\n+  def _get_user_topic_cheats(self):\n+    (_, topics) = self._get_user_topics()\n+    for topic in topics.values():\n+      if topic.topic_name.lower() == self.topic.lower():\n+        with CheatSheetsCache(self.ttl) as cs:\n+          if self.force or topic.is_expired(self.ttl) or not topic.cheats:\n+            log.debug('Fetching user topic cheats from server')\n+            cs.add_or_update_user_topic_sheet(self.user_name,\n+                                              topic.topic_id,\n+                                              topic.topic_name,\n+                                              self.api.user_topic_cheats(self.user_name, topic.topic_id))\n+        return cs.get_user_topic_cheat(self.user_name, topic.topic_id)\n+    self.get_user_topics(False)\n+    raise CommandError('Topic {0} not found'.format(self.topic))\n+\n+  def list_user_topic_cheats(self):\n+    print_util('User: {0}, Topic: {1}'.format(self.user_name, self.topic), 'green', self.colorize)\n+    topic_cheats = self._get_user_topic_cheats()\n+    self.print_cheats(topic_cheats)\n+\n+  def print_cheats(self, topic_cheats):\n+    for cheat in topic_cheats:\n+      print_util(cheat.description, 'blue', self.colorize)\n+      print(cheat.command)\n+\n+  def search_user_topic_cheats(self):\n+    (since_timestamp, user_topic_cheats) = self._get_user_topic_cheats()\n+    print_util('User: {0}, Topic: {1}, Search-Term: {2}, Last fetched: {3} ago'\n+       .format(self.user_name, self.topic, self.search_term, since_time_in_words(since_timestamp)),\n+      'green', self.colorize)\n+\n+    search_results = filter(lambda topic_cheat: self.search_term in topic_cheat.description, user_topic_cheats)","path":"src/python/lib/grepg_client.py","position":72,"original_position":72,"commit_id":"ad1d9db4c5fd8bfdd3e09d3e11b1d103f47ad8d4","original_commit_id":"ad1d9db4c5fd8bfdd3e09d3e11b1d103f47ad8d4","user":{"login":"tejal29","id":1534539,"avatar_url":"https://avatars.githubusercontent.com/u/1534539?v=3","gravatar_id":"","url":"https://api.github.com/users/tejal29","html_url":"https://github.com/tejal29","followers_url":"https://api.github.com/users/tejal29/followers","following_url":"https://api.github.com/users/tejal29/following{/other_user}","gists_url":"https://api.github.com/users/tejal29/gists{/gist_id}","starred_url":"https://api.github.com/users/tejal29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejal29/subscriptions","organizations_url":"https://api.github.com/users/tejal29/orgs","repos_url":"https://api.github.com/users/tejal29/repos","events_url":"https://api.github.com/users/tejal29/events{/privacy}","received_events_url":"https://api.github.com/users/tejal29/received_events","type":"User","site_admin":false},"body":"do \"and\" and \"or\" ","created_at":"2016-07-14T07:07:27Z","updated_at":"2016-07-14T07:07:27Z","html_url":"https://github.com/tejal29/grepg/pull/1#discussion_r70757670","pull_request_url":"https://api.github.com/repos/tejal29/grepg/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/tejal29/grepg/pulls/comments/70757670"},"html":{"href":"https://github.com/tejal29/grepg/pull/1#discussion_r70757670"},"pull_request":{"href":"https://api.github.com/repos/tejal29/grepg/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/tejal29/grepg/pulls/1","id":77408217,"html_url":"https://github.com/tejal29/grepg/pull/1","diff_url":"https://github.com/tejal29/grepg/pull/1.diff","patch_url":"https://github.com/tejal29/grepg/pull/1.patch","issue_url":"https://api.github.com/repos/tejal29/grepg/issues/1","number":1,"state":"open","locked":false,"title":"Demo","user":{"login":"tejal29","id":1534539,"avatar_url":"https://avatars.githubusercontent.com/u/1534539?v=3","gravatar_id":"","url":"https://api.github.com/users/tejal29","html_url":"https://github.com/tejal29","followers_url":"https://api.github.com/users/tejal29/followers","following_url":"https://api.github.com/users/tejal29/following{/other_user}","gists_url":"https://api.github.com/users/tejal29/gists{/gist_id}","starred_url":"https://api.github.com/users/tejal29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejal29/subscriptions","organizations_url":"https://api.github.com/users/tejal29/orgs","repos_url":"https://api.github.com/users/tejal29/repos","events_url":"https://api.github.com/users/tejal29/events{/privacy}","received_events_url":"https://api.github.com/users/tejal29/received_events","type":"User","site_admin":false},"body":"Demo feedback","created_at":"2016-07-14T06:57:14Z","updated_at":"2016-07-14T07:07:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a47c4c37247302575692030f7e13f1d65478648d","assignee":{"login":"tejal29","id":1534539,"avatar_url":"https://avatars.githubusercontent.com/u/1534539?v=3","gravatar_id":"","url":"https://api.github.com/users/tejal29","html_url":"https://github.com/tejal29","followers_url":"https://api.github.com/users/tejal29/followers","following_url":"https://api.github.com/users/tejal29/following{/other_user}","gists_url":"https://api.github.com/users/tejal29/gists{/gist_id}","starred_url":"https://api.github.com/users/tejal29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejal29/subscriptions","organizations_url":"https://api.github.com/users/tejal29/orgs","repos_url":"https://api.github.com/users/tejal29/repos","events_url":"https://api.github.com/users/tejal29/events{/privacy}","received_events_url":"https://api.github.com/users/tejal29/received_events","type":"User","site_admin":false},"assignees":[{"login":"tejal29","id":1534539,"avatar_url":"https://avatars.githubusercontent.com/u/1534539?v=3","gravatar_id":"","url":"https://api.github.com/users/tejal29","html_url":"https://github.com/tejal29","followers_url":"https://api.github.com/users/tejal29/followers","following_url":"https://api.github.com/users/tejal29/following{/other_user}","gists_url":"https://api.github.com/users/tejal29/gists{/gist_id}","starred_url":"https://api.github.com/users/tejal29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejal29/subscriptions","organizations_url":"https://api.github.com/users/tejal29/orgs","repos_url":"https://api.github.com/users/tejal29/repos","events_url":"https://api.github.com/users/tejal29/events{/privacy}","received_events_url":"https://api.github.com/users/tejal29/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/tejal29/grepg/pulls/1/commits","review_comments_url":"https://api.github.com/repos/tejal29/grepg/pulls/1/comments","review_comment_url":"https://api.github.com/repos/tejal29/grepg/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tejal29/grepg/issues/1/comments","statuses_url":"https://api.github.com/repos/tejal29/grepg/statuses/ad1d9db4c5fd8bfdd3e09d3e11b1d103f47ad8d4","head":{"label":"tejal29:demo","ref":"demo","sha":"ad1d9db4c5fd8bfdd3e09d3e11b1d103f47ad8d4","user":{"login":"tejal29","id":1534539,"avatar_url":"https://avatars.githubusercontent.com/u/1534539?v=3","gravatar_id":"","url":"https://api.github.com/users/tejal29","html_url":"https://github.com/tejal29","followers_url":"https://api.github.com/users/tejal29/followers","following_url":"https://api.github.com/users/tejal29/following{/other_user}","gists_url":"https://api.github.com/users/tejal29/gists{/gist_id}","starred_url":"https://api.github.com/users/tejal29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejal29/subscriptions","organizations_url":"https://api.github.com/users/tejal29/orgs","repos_url":"https://api.github.com/users/tejal29/repos","events_url":"https://api.github.com/users/tejal29/events{/privacy}","received_events_url":"https://api.github.com/users/tejal29/received_events","type":"User","site_admin":false},"repo":{"id":62693497,"name":"grepg","full_name":"tejal29/grepg","owner":{"login":"tejal29","id":1534539,"avatar_url":"https://avatars.githubusercontent.com/u/1534539?v=3","gravatar_id":"","url":"https://api.github.com/users/tejal29","html_url":"https://github.com/tejal29","followers_url":"https://api.github.com/users/tejal29/followers","following_url":"https://api.github.com/users/tejal29/following{/other_user}","gists_url":"https://api.github.com/users/tejal29/gists{/gist_id}","starred_url":"https://api.github.com/users/tejal29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejal29/subscriptions","organizations_url":"https://api.github.com/users/tejal29/orgs","repos_url":"https://api.github.com/users/tejal29/repos","events_url":"https://api.github.com/users/tejal29/events{/privacy}","received_events_url":"https://api.github.com/users/tejal29/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tejal29/grepg","description":"Python command line client for greppage","fork":false,"url":"https://api.github.com/repos/tejal29/grepg","forks_url":"https://api.github.com/repos/tejal29/grepg/forks","keys_url":"https://api.github.com/repos/tejal29/grepg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tejal29/grepg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tejal29/grepg/teams","hooks_url":"https://api.github.com/repos/tejal29/grepg/hooks","issue_events_url":"https://api.github.com/repos/tejal29/grepg/issues/events{/number}","events_url":"https://api.github.com/repos/tejal29/grepg/events","assignees_url":"https://api.github.com/repos/tejal29/grepg/assignees{/user}","branches_url":"https://api.github.com/repos/tejal29/grepg/branches{/branch}","tags_url":"https://api.github.com/repos/tejal29/grepg/tags","blobs_url":"https://api.github.com/repos/tejal29/grepg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tejal29/grepg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tejal29/grepg/git/refs{/sha}","trees_url":"https://api.github.com/repos/tejal29/grepg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tejal29/grepg/statuses/{sha}","languages_url":"https://api.github.com/repos/tejal29/grepg/languages","stargazers_url":"https://api.github.com/repos/tejal29/grepg/stargazers","contributors_url":"https://api.github.com/repos/tejal29/grepg/contributors","subscribers_url":"https://api.github.com/repos/tejal29/grepg/subscribers","subscription_url":"https://api.github.com/repos/tejal29/grepg/subscription","commits_url":"https://api.github.com/repos/tejal29/grepg/commits{/sha}","git_commits_url":"https://api.github.com/repos/tejal29/grepg/git/commits{/sha}","comments_url":"https://api.github.com/repos/tejal29/grepg/comments{/number}","issue_comment_url":"https://api.github.com/repos/tejal29/grepg/issues/comments{/number}","contents_url":"https://api.github.com/repos/tejal29/grepg/contents/{+path}","compare_url":"https://api.github.com/repos/tejal29/grepg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tejal29/grepg/merges","archive_url":"https://api.github.com/repos/tejal29/grepg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tejal29/grepg/downloads","issues_url":"https://api.github.com/repos/tejal29/grepg/issues{/number}","pulls_url":"https://api.github.com/repos/tejal29/grepg/pulls{/number}","milestones_url":"https://api.github.com/repos/tejal29/grepg/milestones{/number}","notifications_url":"https://api.github.com/repos/tejal29/grepg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tejal29/grepg/labels{/name}","releases_url":"https://api.github.com/repos/tejal29/grepg/releases{/id}","deployments_url":"https://api.github.com/repos/tejal29/grepg/deployments","created_at":"2016-07-06T05:25:33Z","updated_at":"2016-07-12T01:07:58Z","pushed_at":"2016-07-14T06:57:14Z","git_url":"git://github.com/tejal29/grepg.git","ssh_url":"git@github.com:tejal29/grepg.git","clone_url":"https://github.com/tejal29/grepg.git","svn_url":"https://github.com/tejal29/grepg","homepage":null,"size":3,"stargazers_count":0,"watchers_count":0,"language":"Shell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"tejal29:master","ref":"master","sha":"038ba7a6d800b5b034c5d2a363771e5fbcd67617","user":{"login":"tejal29","id":1534539,"avatar_url":"https://avatars.githubusercontent.com/u/1534539?v=3","gravatar_id":"","url":"https://api.github.com/users/tejal29","html_url":"https://github.com/tejal29","followers_url":"https://api.github.com/users/tejal29/followers","following_url":"https://api.github.com/users/tejal29/following{/other_user}","gists_url":"https://api.github.com/users/tejal29/gists{/gist_id}","starred_url":"https://api.github.com/users/tejal29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejal29/subscriptions","organizations_url":"https://api.github.com/users/tejal29/orgs","repos_url":"https://api.github.com/users/tejal29/repos","events_url":"https://api.github.com/users/tejal29/events{/privacy}","received_events_url":"https://api.github.com/users/tejal29/received_events","type":"User","site_admin":false},"repo":{"id":62693497,"name":"grepg","full_name":"tejal29/grepg","owner":{"login":"tejal29","id":1534539,"avatar_url":"https://avatars.githubusercontent.com/u/1534539?v=3","gravatar_id":"","url":"https://api.github.com/users/tejal29","html_url":"https://github.com/tejal29","followers_url":"https://api.github.com/users/tejal29/followers","following_url":"https://api.github.com/users/tejal29/following{/other_user}","gists_url":"https://api.github.com/users/tejal29/gists{/gist_id}","starred_url":"https://api.github.com/users/tejal29/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejal29/subscriptions","organizations_url":"https://api.github.com/users/tejal29/orgs","repos_url":"https://api.github.com/users/tejal29/repos","events_url":"https://api.github.com/users/tejal29/events{/privacy}","received_events_url":"https://api.github.com/users/tejal29/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tejal29/grepg","description":"Python command line client for greppage","fork":false,"url":"https://api.github.com/repos/tejal29/grepg","forks_url":"https://api.github.com/repos/tejal29/grepg/forks","keys_url":"https://api.github.com/repos/tejal29/grepg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tejal29/grepg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tejal29/grepg/teams","hooks_url":"https://api.github.com/repos/tejal29/grepg/hooks","issue_events_url":"https://api.github.com/repos/tejal29/grepg/issues/events{/number}","events_url":"https://api.github.com/repos/tejal29/grepg/events","assignees_url":"https://api.github.com/repos/tejal29/grepg/assignees{/user}","branches_url":"https://api.github.com/repos/tejal29/grepg/branches{/branch}","tags_url":"https://api.github.com/repos/tejal29/grepg/tags","blobs_url":"https://api.github.com/repos/tejal29/grepg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tejal29/grepg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tejal29/grepg/git/refs{/sha}","trees_url":"https://api.github.com/repos/tejal29/grepg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tejal29/grepg/statuses/{sha}","languages_url":"https://api.github.com/repos/tejal29/grepg/languages","stargazers_url":"https://api.github.com/repos/tejal29/grepg/stargazers","contributors_url":"https://api.github.com/repos/tejal29/grepg/contributors","subscribers_url":"https://api.github.com/repos/tejal29/grepg/subscribers","subscription_url":"https://api.github.com/repos/tejal29/grepg/subscription","commits_url":"https://api.github.com/repos/tejal29/grepg/commits{/sha}","git_commits_url":"https://api.github.com/repos/tejal29/grepg/git/commits{/sha}","comments_url":"https://api.github.com/repos/tejal29/grepg/comments{/number}","issue_comment_url":"https://api.github.com/repos/tejal29/grepg/issues/comments{/number}","contents_url":"https://api.github.com/repos/tejal29/grepg/contents/{+path}","compare_url":"https://api.github.com/repos/tejal29/grepg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tejal29/grepg/merges","archive_url":"https://api.github.com/repos/tejal29/grepg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tejal29/grepg/downloads","issues_url":"https://api.github.com/repos/tejal29/grepg/issues{/number}","pulls_url":"https://api.github.com/repos/tejal29/grepg/pulls{/number}","milestones_url":"https://api.github.com/repos/tejal29/grepg/milestones{/number}","notifications_url":"https://api.github.com/repos/tejal29/grepg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tejal29/grepg/labels{/name}","releases_url":"https://api.github.com/repos/tejal29/grepg/releases{/id}","deployments_url":"https://api.github.com/repos/tejal29/grepg/deployments","created_at":"2016-07-06T05:25:33Z","updated_at":"2016-07-12T01:07:58Z","pushed_at":"2016-07-14T06:57:14Z","git_url":"git://github.com/tejal29/grepg.git","ssh_url":"git@github.com:tejal29/grepg.git","clone_url":"https://github.com/tejal29/grepg.git","svn_url":"https://github.com/tejal29/grepg","homepage":null,"size":3,"stargazers_count":0,"watchers_count":0,"language":"Shell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tejal29/grepg/pulls/1"},"html":{"href":"https://github.com/tejal29/grepg/pull/1"},"issue":{"href":"https://api.github.com/repos/tejal29/grepg/issues/1"},"comments":{"href":"https://api.github.com/repos/tejal29/grepg/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/tejal29/grepg/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/tejal29/grepg/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tejal29/grepg/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/tejal29/grepg/statuses/ad1d9db4c5fd8bfdd3e09d3e11b1d103f47ad8d4"}}}}
{"actor":{"display_login":"tejal29"}}