{"action":"created","comment":{"url":"https://api.github.com/repos/directactioneverywhere/server/pulls/comments/52959463","id":52959463,"diff_hunk":"@@ -0,0 +1,251 @@\n+\"\"\"Manages dashboard data.\n+Pulls event data from facebook, saves data as csvs in s3,\n+loads data into the db, and generates data views.\"\"\"\n+import csv\n+import io\n+import json\n+import hashlib\n+import os\n+import time\n+\n+import argparse\n+from boto.s3.connection import S3Connection\n+from boto.s3.key import Key\n+import requests\n+import psycopg2\n+\n+from airtable.airtable import get_all_records\n+\n+S3_BUCKET = \"dxe-backup\"\n+S3_BACKUP_DIR = \"dashboard\"\n+S3_ACCESS_KEY = os.environ[\"AIRTABLE_BACKUP_AWS_ACCESS_KEY_ID\"]\n+S3_SECRET_KEY = os.environ[\"AIRTABLE_BACKUP_AWS_SECRET_ACCESS_KEY\"]\n+\n+\n+def chunks(l, n):\n+    \"\"\"Yield successive n-sized chunks from l.\"\"\"\n+    for i in xrange(0, len(l), n):\n+        yield l[i:i+n]\n+\n+\n+def links_to_ids(links):\n+    \"\"\"Uses the Facebook Graph API to get group/page's ids from their links\"\"\"\n+    # This uses's the batch request feature\n+    # (https://developers.facebook.com/docs/graph-api/making-multiple-requests)\n+    # to make many logical requests within one http request, saving the overhead\n+    # cost\n+\n+    ids = []\n+    for links_subset in chunks(links, 50):  # batch limit is 50\n+        reqs = ['{{\"method\":\"GET\", \"relative_url\":\"{}\"}}'.format(link) for link in links_subset]\n+        batch_req = '[' + \",\".join(reqs) + ']'\n+\n+        r = requests.post(\n+            \"https://graph.facebook.com/v2.5\",\n+            data={\"batch\": batch_req},\n+            headers={\"Authorization\": \"Bearer {}\".format(os.environ[\"FACEBOOK_APP_ACCESS_TOKEN\"])}\n+        )\n+        data = r.json()\n+        for i, res in enumerate(data):\n+            community = json.loads(res['body'])['id']\n+            if community.startswith(\"http\"):\n+                # If the id here is actually a link, then that means it was a fb group. If it's an\n+                # id, then it was a fb page. The response format is different for each.\n+                community = json.loads(res['body'])['og_object']['id']\n+            ids.append(community)\n+    return ids\n+\n+\n+def get_facebook_chapter_links():\n+    \"\"\"Grab the facebook links for each local chapter from airtable.\"\"\"\n+    raw_data = get_all_records(\"Chapters\", \"Main View\")\n+    chapter_links = []\n+    for row in raw_data:\n+        fields = row[\"fields\"]\n+        if \"Facebook\" in fields:\n+            chapter_links.append(fields[\"Facebook\"])\n+    return list(set(chapter_links))  # some differnent chapters use the same facebook page, remove dups\n+\n+\n+def get_events(_id):","path":"dashboard/generate_dashboard_data.py","position":70,"original_position":70,"commit_id":"26af931cb9a8c742ff76d4ba4bd69bcfa6cc75d3","original_commit_id":"26af931cb9a8c742ff76d4ba4bd69bcfa6cc75d3","user":{"login":"mjperrone","id":3848371,"avatar_url":"https://avatars.githubusercontent.com/u/3848371?v=3","gravatar_id":"","url":"https://api.github.com/users/mjperrone","html_url":"https://github.com/mjperrone","followers_url":"https://api.github.com/users/mjperrone/followers","following_url":"https://api.github.com/users/mjperrone/following{/other_user}","gists_url":"https://api.github.com/users/mjperrone/gists{/gist_id}","starred_url":"https://api.github.com/users/mjperrone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjperrone/subscriptions","organizations_url":"https://api.github.com/users/mjperrone/orgs","repos_url":"https://api.github.com/users/mjperrone/repos","events_url":"https://api.github.com/users/mjperrone/events{/privacy}","received_events_url":"https://api.github.com/users/mjperrone/received_events","type":"User","site_admin":false},"body":"will do","created_at":"2016-02-16T01:24:30Z","updated_at":"2016-02-16T01:24:30Z","html_url":"https://github.com/directactioneverywhere/server/pull/14#discussion_r52959463","pull_request_url":"https://api.github.com/repos/directactioneverywhere/server/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/directactioneverywhere/server/pulls/comments/52959463"},"html":{"href":"https://github.com/directactioneverywhere/server/pull/14#discussion_r52959463"},"pull_request":{"href":"https://api.github.com/repos/directactioneverywhere/server/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/directactioneverywhere/server/pulls/14","id":59410047,"html_url":"https://github.com/directactioneverywhere/server/pull/14","diff_url":"https://github.com/directactioneverywhere/server/pull/14.diff","patch_url":"https://github.com/directactioneverywhere/server/pull/14.patch","issue_url":"https://api.github.com/repos/directactioneverywhere/server/issues/14","number":14,"state":"open","locked":false,"title":"Dashboard backend","user":{"login":"mjperrone","id":3848371,"avatar_url":"https://avatars.githubusercontent.com/u/3848371?v=3","gravatar_id":"","url":"https://api.github.com/users/mjperrone","html_url":"https://github.com/mjperrone","followers_url":"https://api.github.com/users/mjperrone/followers","following_url":"https://api.github.com/users/mjperrone/following{/other_user}","gists_url":"https://api.github.com/users/mjperrone/gists{/gist_id}","starred_url":"https://api.github.com/users/mjperrone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjperrone/subscriptions","organizations_url":"https://api.github.com/users/mjperrone/orgs","repos_url":"https://api.github.com/users/mjperrone/repos","events_url":"https://api.github.com/users/mjperrone/events{/privacy}","received_events_url":"https://api.github.com/users/mjperrone/received_events","type":"User","site_admin":false},"body":"Grabs basic data on  DxE chapter fb groups, their events, and  anonomyzed  attendees using the Facebook Graph API, then sticks that into a postgres database, and then outputs a csv that counts the number of attendees per month, and exposes that on the server.\r\n","created_at":"2016-02-15T20:26:56Z","updated_at":"2016-02-16T01:24:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"71db55ab3ef9d5d324331fab3c193f05c584aa6a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/directactioneverywhere/server/pulls/14/commits","review_comments_url":"https://api.github.com/repos/directactioneverywhere/server/pulls/14/comments","review_comment_url":"https://api.github.com/repos/directactioneverywhere/server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/directactioneverywhere/server/issues/14/comments","statuses_url":"https://api.github.com/repos/directactioneverywhere/server/statuses/26af931cb9a8c742ff76d4ba4bd69bcfa6cc75d3","head":{"label":"directactioneverywhere:dashboard","ref":"dashboard","sha":"26af931cb9a8c742ff76d4ba4bd69bcfa6cc75d3","user":{"login":"directactioneverywhere","id":14240073,"avatar_url":"https://avatars.githubusercontent.com/u/14240073?v=3","gravatar_id":"","url":"https://api.github.com/users/directactioneverywhere","html_url":"https://github.com/directactioneverywhere","followers_url":"https://api.github.com/users/directactioneverywhere/followers","following_url":"https://api.github.com/users/directactioneverywhere/following{/other_user}","gists_url":"https://api.github.com/users/directactioneverywhere/gists{/gist_id}","starred_url":"https://api.github.com/users/directactioneverywhere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/directactioneverywhere/subscriptions","organizations_url":"https://api.github.com/users/directactioneverywhere/orgs","repos_url":"https://api.github.com/users/directactioneverywhere/repos","events_url":"https://api.github.com/users/directactioneverywhere/events{/privacy}","received_events_url":"https://api.github.com/users/directactioneverywhere/received_events","type":"Organization","site_admin":false},"repo":{"id":42635131,"name":"server","full_name":"directactioneverywhere/server","owner":{"login":"directactioneverywhere","id":14240073,"avatar_url":"https://avatars.githubusercontent.com/u/14240073?v=3","gravatar_id":"","url":"https://api.github.com/users/directactioneverywhere","html_url":"https://github.com/directactioneverywhere","followers_url":"https://api.github.com/users/directactioneverywhere/followers","following_url":"https://api.github.com/users/directactioneverywhere/following{/other_user}","gists_url":"https://api.github.com/users/directactioneverywhere/gists{/gist_id}","starred_url":"https://api.github.com/users/directactioneverywhere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/directactioneverywhere/subscriptions","organizations_url":"https://api.github.com/users/directactioneverywhere/orgs","repos_url":"https://api.github.com/users/directactioneverywhere/repos","events_url":"https://api.github.com/users/directactioneverywhere/events{/privacy}","received_events_url":"https://api.github.com/users/directactioneverywhere/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/directactioneverywhere/server","description":"The dxetech server!","fork":false,"url":"https://api.github.com/repos/directactioneverywhere/server","forks_url":"https://api.github.com/repos/directactioneverywhere/server/forks","keys_url":"https://api.github.com/repos/directactioneverywhere/server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/directactioneverywhere/server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/directactioneverywhere/server/teams","hooks_url":"https://api.github.com/repos/directactioneverywhere/server/hooks","issue_events_url":"https://api.github.com/repos/directactioneverywhere/server/issues/events{/number}","events_url":"https://api.github.com/repos/directactioneverywhere/server/events","assignees_url":"https://api.github.com/repos/directactioneverywhere/server/assignees{/user}","branches_url":"https://api.github.com/repos/directactioneverywhere/server/branches{/branch}","tags_url":"https://api.github.com/repos/directactioneverywhere/server/tags","blobs_url":"https://api.github.com/repos/directactioneverywhere/server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/directactioneverywhere/server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/directactioneverywhere/server/git/refs{/sha}","trees_url":"https://api.github.com/repos/directactioneverywhere/server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/directactioneverywhere/server/statuses/{sha}","languages_url":"https://api.github.com/repos/directactioneverywhere/server/languages","stargazers_url":"https://api.github.com/repos/directactioneverywhere/server/stargazers","contributors_url":"https://api.github.com/repos/directactioneverywhere/server/contributors","subscribers_url":"https://api.github.com/repos/directactioneverywhere/server/subscribers","subscription_url":"https://api.github.com/repos/directactioneverywhere/server/subscription","commits_url":"https://api.github.com/repos/directactioneverywhere/server/commits{/sha}","git_commits_url":"https://api.github.com/repos/directactioneverywhere/server/git/commits{/sha}","comments_url":"https://api.github.com/repos/directactioneverywhere/server/comments{/number}","issue_comment_url":"https://api.github.com/repos/directactioneverywhere/server/issues/comments{/number}","contents_url":"https://api.github.com/repos/directactioneverywhere/server/contents/{+path}","compare_url":"https://api.github.com/repos/directactioneverywhere/server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/directactioneverywhere/server/merges","archive_url":"https://api.github.com/repos/directactioneverywhere/server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/directactioneverywhere/server/downloads","issues_url":"https://api.github.com/repos/directactioneverywhere/server/issues{/number}","pulls_url":"https://api.github.com/repos/directactioneverywhere/server/pulls{/number}","milestones_url":"https://api.github.com/repos/directactioneverywhere/server/milestones{/number}","notifications_url":"https://api.github.com/repos/directactioneverywhere/server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/directactioneverywhere/server/labels{/name}","releases_url":"https://api.github.com/repos/directactioneverywhere/server/releases{/id}","deployments_url":"https://api.github.com/repos/directactioneverywhere/server/deployments","created_at":"2015-09-17T04:35:36Z","updated_at":"2016-01-22T06:20:17Z","pushed_at":"2016-02-15T20:26:56Z","git_url":"git://github.com/directactioneverywhere/server.git","ssh_url":"git@github.com:directactioneverywhere/server.git","clone_url":"https://github.com/directactioneverywhere/server.git","svn_url":"https://github.com/directactioneverywhere/server","homepage":null,"size":257,"stargazers_count":1,"watchers_count":1,"language":"Python","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":1,"default_branch":"master"}},"base":{"label":"directactioneverywhere:master","ref":"master","sha":"b782603cc80fc6a484c817278774fbbaf3f6080d","user":{"login":"directactioneverywhere","id":14240073,"avatar_url":"https://avatars.githubusercontent.com/u/14240073?v=3","gravatar_id":"","url":"https://api.github.com/users/directactioneverywhere","html_url":"https://github.com/directactioneverywhere","followers_url":"https://api.github.com/users/directactioneverywhere/followers","following_url":"https://api.github.com/users/directactioneverywhere/following{/other_user}","gists_url":"https://api.github.com/users/directactioneverywhere/gists{/gist_id}","starred_url":"https://api.github.com/users/directactioneverywhere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/directactioneverywhere/subscriptions","organizations_url":"https://api.github.com/users/directactioneverywhere/orgs","repos_url":"https://api.github.com/users/directactioneverywhere/repos","events_url":"https://api.github.com/users/directactioneverywhere/events{/privacy}","received_events_url":"https://api.github.com/users/directactioneverywhere/received_events","type":"Organization","site_admin":false},"repo":{"id":42635131,"name":"server","full_name":"directactioneverywhere/server","owner":{"login":"directactioneverywhere","id":14240073,"avatar_url":"https://avatars.githubusercontent.com/u/14240073?v=3","gravatar_id":"","url":"https://api.github.com/users/directactioneverywhere","html_url":"https://github.com/directactioneverywhere","followers_url":"https://api.github.com/users/directactioneverywhere/followers","following_url":"https://api.github.com/users/directactioneverywhere/following{/other_user}","gists_url":"https://api.github.com/users/directactioneverywhere/gists{/gist_id}","starred_url":"https://api.github.com/users/directactioneverywhere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/directactioneverywhere/subscriptions","organizations_url":"https://api.github.com/users/directactioneverywhere/orgs","repos_url":"https://api.github.com/users/directactioneverywhere/repos","events_url":"https://api.github.com/users/directactioneverywhere/events{/privacy}","received_events_url":"https://api.github.com/users/directactioneverywhere/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/directactioneverywhere/server","description":"The dxetech server!","fork":false,"url":"https://api.github.com/repos/directactioneverywhere/server","forks_url":"https://api.github.com/repos/directactioneverywhere/server/forks","keys_url":"https://api.github.com/repos/directactioneverywhere/server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/directactioneverywhere/server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/directactioneverywhere/server/teams","hooks_url":"https://api.github.com/repos/directactioneverywhere/server/hooks","issue_events_url":"https://api.github.com/repos/directactioneverywhere/server/issues/events{/number}","events_url":"https://api.github.com/repos/directactioneverywhere/server/events","assignees_url":"https://api.github.com/repos/directactioneverywhere/server/assignees{/user}","branches_url":"https://api.github.com/repos/directactioneverywhere/server/branches{/branch}","tags_url":"https://api.github.com/repos/directactioneverywhere/server/tags","blobs_url":"https://api.github.com/repos/directactioneverywhere/server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/directactioneverywhere/server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/directactioneverywhere/server/git/refs{/sha}","trees_url":"https://api.github.com/repos/directactioneverywhere/server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/directactioneverywhere/server/statuses/{sha}","languages_url":"https://api.github.com/repos/directactioneverywhere/server/languages","stargazers_url":"https://api.github.com/repos/directactioneverywhere/server/stargazers","contributors_url":"https://api.github.com/repos/directactioneverywhere/server/contributors","subscribers_url":"https://api.github.com/repos/directactioneverywhere/server/subscribers","subscription_url":"https://api.github.com/repos/directactioneverywhere/server/subscription","commits_url":"https://api.github.com/repos/directactioneverywhere/server/commits{/sha}","git_commits_url":"https://api.github.com/repos/directactioneverywhere/server/git/commits{/sha}","comments_url":"https://api.github.com/repos/directactioneverywhere/server/comments{/number}","issue_comment_url":"https://api.github.com/repos/directactioneverywhere/server/issues/comments{/number}","contents_url":"https://api.github.com/repos/directactioneverywhere/server/contents/{+path}","compare_url":"https://api.github.com/repos/directactioneverywhere/server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/directactioneverywhere/server/merges","archive_url":"https://api.github.com/repos/directactioneverywhere/server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/directactioneverywhere/server/downloads","issues_url":"https://api.github.com/repos/directactioneverywhere/server/issues{/number}","pulls_url":"https://api.github.com/repos/directactioneverywhere/server/pulls{/number}","milestones_url":"https://api.github.com/repos/directactioneverywhere/server/milestones{/number}","notifications_url":"https://api.github.com/repos/directactioneverywhere/server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/directactioneverywhere/server/labels{/name}","releases_url":"https://api.github.com/repos/directactioneverywhere/server/releases{/id}","deployments_url":"https://api.github.com/repos/directactioneverywhere/server/deployments","created_at":"2015-09-17T04:35:36Z","updated_at":"2016-01-22T06:20:17Z","pushed_at":"2016-02-15T20:26:56Z","git_url":"git://github.com/directactioneverywhere/server.git","ssh_url":"git@github.com:directactioneverywhere/server.git","clone_url":"https://github.com/directactioneverywhere/server.git","svn_url":"https://github.com/directactioneverywhere/server","homepage":null,"size":257,"stargazers_count":1,"watchers_count":1,"language":"Python","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":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/directactioneverywhere/server/pulls/14"},"html":{"href":"https://github.com/directactioneverywhere/server/pull/14"},"issue":{"href":"https://api.github.com/repos/directactioneverywhere/server/issues/14"},"comments":{"href":"https://api.github.com/repos/directactioneverywhere/server/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/directactioneverywhere/server/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/directactioneverywhere/server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/directactioneverywhere/server/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/directactioneverywhere/server/statuses/26af931cb9a8c742ff76d4ba4bd69bcfa6cc75d3"}}}}