{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/kuma/pulls/comments/74776713","id":74776713,"diff_hunk":"@@ -59,3 +69,80 @@ def tidy_content(content):\n         return tidied.decode('utf-8'), errors\n     else:\n         return content\n+\n+\n+def analytics_upageviews(revision_ids, start_date, end_date=None):\n+    \"\"\"Given a sequence of document revision IDs, returns a dict matching\n+    those with the number of users Google Analytics thinks has visited\n+    each revision since start_date.\n+\n+    \"\"\"\n+\n+    scopes = ['https://www.googleapis.com/auth/analytics.readonly']\n+\n+    try:\n+        ga_cred_dict = json.loads(config.GOOGLE_ANALYTICS_CREDENTIALS)\n+    except (ValueError, TypeError):\n+        raise ImproperlyConfigured(\n+            \"GOOGLE_ANALYTICS_CREDENTIALS Constance setting is badly formed.\")\n+    if not ga_cred_dict:\n+        raise ImproperlyConfigured(\n+            \"An empty GOOGLE_ANALYTICS_CREDENTIALS Constance setting is not permitted.\")\n+\n+    credentials = ServiceAccountCredentials.from_json_keyfile_dict(ga_cred_dict,\n+                                                                   scopes=scopes)\n+    http_auth = credentials.authorize(Http())\n+    service = build('analyticsreporting', 'v4', http=http_auth)\n+\n+    end_date = datetime.date.today().isoformat()\n+    if hasattr(start_date, 'date'):\n+        start_date = start_date.date()","path":"kuma/wiki/utils.py","position":48,"original_position":48,"commit_id":"504b2ce06f0c7dae388623b47db478ba2f02f505","original_commit_id":"504b2ce06f0c7dae388623b47db478ba2f02f505","user":{"login":"jwhitlock","id":286017,"avatar_url":"https://avatars.githubusercontent.com/u/286017?v=3","gravatar_id":"","url":"https://api.github.com/users/jwhitlock","html_url":"https://github.com/jwhitlock","followers_url":"https://api.github.com/users/jwhitlock/followers","following_url":"https://api.github.com/users/jwhitlock/following{/other_user}","gists_url":"https://api.github.com/users/jwhitlock/gists{/gist_id}","starred_url":"https://api.github.com/users/jwhitlock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwhitlock/subscriptions","organizations_url":"https://api.github.com/users/jwhitlock/orgs","repos_url":"https://api.github.com/users/jwhitlock/repos","events_url":"https://api.github.com/users/jwhitlock/events{/privacy}","received_events_url":"https://api.github.com/users/jwhitlock/received_events","type":"User","site_admin":false},"body":"👍 on auto-fixing ``datetime`` to ``date``. The same should be used on ``end_date``.","created_at":"2016-08-15T15:11:33Z","updated_at":"2016-08-15T15:11:33Z","html_url":"https://github.com/mozilla/kuma/pull/3925#discussion_r74776713","pull_request_url":"https://api.github.com/repos/mozilla/kuma/pulls/3925","_links":{"self":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/comments/74776713"},"html":{"href":"https://github.com/mozilla/kuma/pull/3925#discussion_r74776713"},"pull_request":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/3925"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/kuma/pulls/3925","id":79784070,"html_url":"https://github.com/mozilla/kuma/pull/3925","diff_url":"https://github.com/mozilla/kuma/pull/3925.diff","patch_url":"https://github.com/mozilla/kuma/pull/3925.patch","issue_url":"https://api.github.com/repos/mozilla/kuma/issues/3925","number":3925,"state":"open","locked":false,"title":"Add the ability to query Google Analytics for the number of users affected by spam","user":{"login":"jbradberry","id":685957,"avatar_url":"https://avatars.githubusercontent.com/u/685957?v=3","gravatar_id":"","url":"https://api.github.com/users/jbradberry","html_url":"https://github.com/jbradberry","followers_url":"https://api.github.com/users/jbradberry/followers","following_url":"https://api.github.com/users/jbradberry/following{/other_user}","gists_url":"https://api.github.com/users/jbradberry/gists{/gist_id}","starred_url":"https://api.github.com/users/jbradberry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbradberry/subscriptions","organizations_url":"https://api.github.com/users/jbradberry/orgs","repos_url":"https://api.github.com/users/jbradberry/repos","events_url":"https://api.github.com/users/jbradberry/events{/privacy}","received_events_url":"https://api.github.com/users/jbradberry/received_events","type":"User","site_admin":false},"body":"https://tree.taiga.io/project/viya-mdn-durable-team/task/353","created_at":"2016-08-02T18:24:39Z","updated_at":"2016-08-15T15:11:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30775e41a166e04b8fad7dbee02134fcdefcd269","assignee":{"login":"jwhitlock","id":286017,"avatar_url":"https://avatars.githubusercontent.com/u/286017?v=3","gravatar_id":"","url":"https://api.github.com/users/jwhitlock","html_url":"https://github.com/jwhitlock","followers_url":"https://api.github.com/users/jwhitlock/followers","following_url":"https://api.github.com/users/jwhitlock/following{/other_user}","gists_url":"https://api.github.com/users/jwhitlock/gists{/gist_id}","starred_url":"https://api.github.com/users/jwhitlock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwhitlock/subscriptions","organizations_url":"https://api.github.com/users/jwhitlock/orgs","repos_url":"https://api.github.com/users/jwhitlock/repos","events_url":"https://api.github.com/users/jwhitlock/events{/privacy}","received_events_url":"https://api.github.com/users/jwhitlock/received_events","type":"User","site_admin":false},"assignees":[{"login":"jwhitlock","id":286017,"avatar_url":"https://avatars.githubusercontent.com/u/286017?v=3","gravatar_id":"","url":"https://api.github.com/users/jwhitlock","html_url":"https://github.com/jwhitlock","followers_url":"https://api.github.com/users/jwhitlock/followers","following_url":"https://api.github.com/users/jwhitlock/following{/other_user}","gists_url":"https://api.github.com/users/jwhitlock/gists{/gist_id}","starred_url":"https://api.github.com/users/jwhitlock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwhitlock/subscriptions","organizations_url":"https://api.github.com/users/jwhitlock/orgs","repos_url":"https://api.github.com/users/jwhitlock/repos","events_url":"https://api.github.com/users/jwhitlock/events{/privacy}","received_events_url":"https://api.github.com/users/jwhitlock/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/kuma/pulls/3925/commits","review_comments_url":"https://api.github.com/repos/mozilla/kuma/pulls/3925/comments","review_comment_url":"https://api.github.com/repos/mozilla/kuma/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/kuma/issues/3925/comments","statuses_url":"https://api.github.com/repos/mozilla/kuma/statuses/504b2ce06f0c7dae388623b47db478ba2f02f505","head":{"label":"caktus:count-users-affected-by-spam","ref":"count-users-affected-by-spam","sha":"504b2ce06f0c7dae388623b47db478ba2f02f505","user":{"login":"caktus","id":242157,"avatar_url":"https://avatars.githubusercontent.com/u/242157?v=3","gravatar_id":"","url":"https://api.github.com/users/caktus","html_url":"https://github.com/caktus","followers_url":"https://api.github.com/users/caktus/followers","following_url":"https://api.github.com/users/caktus/following{/other_user}","gists_url":"https://api.github.com/users/caktus/gists{/gist_id}","starred_url":"https://api.github.com/users/caktus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caktus/subscriptions","organizations_url":"https://api.github.com/users/caktus/orgs","repos_url":"https://api.github.com/users/caktus/repos","events_url":"https://api.github.com/users/caktus/events{/privacy}","received_events_url":"https://api.github.com/users/caktus/received_events","type":"Organization","site_admin":false},"repo":{"id":57151872,"name":"kuma","full_name":"caktus/kuma","owner":{"login":"caktus","id":242157,"avatar_url":"https://avatars.githubusercontent.com/u/242157?v=3","gravatar_id":"","url":"https://api.github.com/users/caktus","html_url":"https://github.com/caktus","followers_url":"https://api.github.com/users/caktus/followers","following_url":"https://api.github.com/users/caktus/following{/other_user}","gists_url":"https://api.github.com/users/caktus/gists{/gist_id}","starred_url":"https://api.github.com/users/caktus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caktus/subscriptions","organizations_url":"https://api.github.com/users/caktus/orgs","repos_url":"https://api.github.com/users/caktus/repos","events_url":"https://api.github.com/users/caktus/events{/privacy}","received_events_url":"https://api.github.com/users/caktus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caktus/kuma","description":"The project that powers MDN.","fork":true,"url":"https://api.github.com/repos/caktus/kuma","forks_url":"https://api.github.com/repos/caktus/kuma/forks","keys_url":"https://api.github.com/repos/caktus/kuma/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caktus/kuma/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caktus/kuma/teams","hooks_url":"https://api.github.com/repos/caktus/kuma/hooks","issue_events_url":"https://api.github.com/repos/caktus/kuma/issues/events{/number}","events_url":"https://api.github.com/repos/caktus/kuma/events","assignees_url":"https://api.github.com/repos/caktus/kuma/assignees{/user}","branches_url":"https://api.github.com/repos/caktus/kuma/branches{/branch}","tags_url":"https://api.github.com/repos/caktus/kuma/tags","blobs_url":"https://api.github.com/repos/caktus/kuma/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caktus/kuma/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caktus/kuma/git/refs{/sha}","trees_url":"https://api.github.com/repos/caktus/kuma/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caktus/kuma/statuses/{sha}","languages_url":"https://api.github.com/repos/caktus/kuma/languages","stargazers_url":"https://api.github.com/repos/caktus/kuma/stargazers","contributors_url":"https://api.github.com/repos/caktus/kuma/contributors","subscribers_url":"https://api.github.com/repos/caktus/kuma/subscribers","subscription_url":"https://api.github.com/repos/caktus/kuma/subscription","commits_url":"https://api.github.com/repos/caktus/kuma/commits{/sha}","git_commits_url":"https://api.github.com/repos/caktus/kuma/git/commits{/sha}","comments_url":"https://api.github.com/repos/caktus/kuma/comments{/number}","issue_comment_url":"https://api.github.com/repos/caktus/kuma/issues/comments{/number}","contents_url":"https://api.github.com/repos/caktus/kuma/contents/{+path}","compare_url":"https://api.github.com/repos/caktus/kuma/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caktus/kuma/merges","archive_url":"https://api.github.com/repos/caktus/kuma/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caktus/kuma/downloads","issues_url":"https://api.github.com/repos/caktus/kuma/issues{/number}","pulls_url":"https://api.github.com/repos/caktus/kuma/pulls{/number}","milestones_url":"https://api.github.com/repos/caktus/kuma/milestones{/number}","notifications_url":"https://api.github.com/repos/caktus/kuma/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caktus/kuma/labels{/name}","releases_url":"https://api.github.com/repos/caktus/kuma/releases{/id}","deployments_url":"https://api.github.com/repos/caktus/kuma/deployments","created_at":"2016-04-26T18:22:58Z","updated_at":"2016-04-26T18:23:03Z","pushed_at":"2016-08-12T19:45:10Z","git_url":"git://github.com/caktus/kuma.git","ssh_url":"git@github.com:caktus/kuma.git","clone_url":"https://github.com/caktus/kuma.git","svn_url":"https://github.com/caktus/kuma","homepage":"https://developer.mozilla.org","size":162669,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"mozilla:master","ref":"master","sha":"5b7515f55f8c135d58cf96bdd29f2d0a8b07198e","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":1352520,"name":"kuma","full_name":"mozilla/kuma","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/kuma","description":"The project that powers MDN.","fork":false,"url":"https://api.github.com/repos/mozilla/kuma","forks_url":"https://api.github.com/repos/mozilla/kuma/forks","keys_url":"https://api.github.com/repos/mozilla/kuma/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/kuma/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/kuma/teams","hooks_url":"https://api.github.com/repos/mozilla/kuma/hooks","issue_events_url":"https://api.github.com/repos/mozilla/kuma/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/kuma/events","assignees_url":"https://api.github.com/repos/mozilla/kuma/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/kuma/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/kuma/tags","blobs_url":"https://api.github.com/repos/mozilla/kuma/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/kuma/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/kuma/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/kuma/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/kuma/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/kuma/languages","stargazers_url":"https://api.github.com/repos/mozilla/kuma/stargazers","contributors_url":"https://api.github.com/repos/mozilla/kuma/contributors","subscribers_url":"https://api.github.com/repos/mozilla/kuma/subscribers","subscription_url":"https://api.github.com/repos/mozilla/kuma/subscription","commits_url":"https://api.github.com/repos/mozilla/kuma/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/kuma/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/kuma/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/kuma/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/kuma/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/kuma/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/kuma/merges","archive_url":"https://api.github.com/repos/mozilla/kuma/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/kuma/downloads","issues_url":"https://api.github.com/repos/mozilla/kuma/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/kuma/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/kuma/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/kuma/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/kuma/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/kuma/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla/kuma/deployments","created_at":"2011-02-10T21:48:06Z","updated_at":"2016-08-14T13:42:40Z","pushed_at":"2016-08-15T15:04:33Z","git_url":"git://github.com/mozilla/kuma.git","ssh_url":"git@github.com:mozilla/kuma.git","clone_url":"https://github.com/mozilla/kuma.git","svn_url":"https://github.com/mozilla/kuma","homepage":"https://developer.mozilla.org","size":177307,"stargazers_count":833,"watchers_count":833,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":514,"mirror_url":null,"open_issues_count":15,"forks":514,"open_issues":15,"watchers":833,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/3925"},"html":{"href":"https://github.com/mozilla/kuma/pull/3925"},"issue":{"href":"https://api.github.com/repos/mozilla/kuma/issues/3925"},"comments":{"href":"https://api.github.com/repos/mozilla/kuma/issues/3925/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/3925/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/3925/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/kuma/statuses/504b2ce06f0c7dae388623b47db478ba2f02f505"}}}}
{"actor":{"display_login":"jwhitlock"}}