{"action":"created","comment":{"url":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/comments/236860856","pull_request_review_id":179027402,"id":236860856,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNjg2MDg1Ng==","diff_hunk":"@@ -0,0 +1,283 @@\n+import requests\n+import json\n+import os\n+import sys\n+import urllib\n+import logging\n+\n+logger = logging.getLogger(__name__)\n+\n+DRIVING_DISTANCE_TEXT_KEY = \"Driving_distance\"\n+DRIVING_TIME_TEXT_KEY = \"Driving_time\"\n+\n+def generate_access_token():\n+    \"\"\"\n+    Generates a temporary access token fro ArcGIS REST APIs\n+\n+    :return: String containing temporary access token\n+    \"\"\"\n+\n+    try:\n+        client_id = os.getenv('ARCGIS_CLIENT_ID')\n+    except:\n+        logger.debug(\"ARCGIS_CLIENT_ID environment variable not set\")\n+        return None\n+\n+    try:\n+        client_secret = os.getenv('ARCGIS_CLIENT_SECRET')\n+    except:\n+        logger.debug(\"ARCGIS_CLIENT_SECRET environment variable not set\")\n+        return None\n+\n+    payload = {\n+        'client_id': client_id,\n+        'client_secret' : client_secret, \n+        'grant_type' : 'client_credentials'\n+        }\n+\n+    headers = {\n+        'content-type': \"application/x-www-form-urlencoded\",\n+        'accept': \"application/json\",\n+        'cache-control': \"no-cache\"\n+        }\n+\n+    base_url = \"https://www.arcgis.com/sharing/rest/oauth2/token\"\n+    response = _post_request(base_url, payload, headers)\n+    if response.status_code != 200:\n+        logger.debug(\"Response Error: {}, Response: {}\".format(str(response.status_code), response.text))\n+        return None\n+    else:\n+        response_json = response.json()\n+        access_token = response_json['access_token']\n+        return access_token\n+    \n+\n+\n+\n+def find_closest_route(api_access_token, origin_address, destination_addresses):\n+    \"\"\"\n+    Finds the closest route, by driving distance,\n+    given the coordinates of an origin and possible destinations\n+\n+    :param api_access_token: String containing temporary ArcGIS REST API access token\n+    :param origin_address: Dictionary containing coordinates and address string of origin\n+    :param destination_addresses: Dictionary with (x, y) coordinate values as the keys,\n+        and the associated address string as the values\n+    :return: Dictionary containing address, driving time and driving distance of closest destination\n+    \"\"\"\n+    logger.debug(\"api_access_token: {} \".format(api_access_token) \\\n+                + \"origin_address: {} \".format(str(origin_address)) \\\n+                + \"destination_addresses: {}\".format(str(destination_addresses))\n+            )\n+\n+    base_url = \"https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World/solveClosestFacility\"\n+    \n+    # (x, y) coordinates of origin address\n+    incidents = \"{},{}\".format(origin_address['x'], origin_address['y'])\n+\n+    # List of (x, y) coordinates of possible destinations\n+    facility_list = []\n+    facility_key_list = []\n+    for k in destination_addresses.keys():\n+        if k[0] != \"\" and k[1] != \"\":\n+            temp_str = \"{},{}\".format(k[0], k[1])\n+            facility_list.append(temp_str)\n+            facility_key_list.append(k)\n+    \n+    # Separate destination coordinates with \";\"\n+    facilities = \";\".join(facility_list)\n+    params = {\n+            'f': 'json',\n+            'token': api_access_token,\n+            'returnDirections': 'false',\n+            'returnCFRoutes': 'true',\n+            'incidents': incidents,\n+            'facilities': facilities\n+            }\n+\n+    formatted_tuple = format_multipart_form_request(base_url, params)\n+    body_as_string = formatted_tuple[0]\n+    updated_header = formatted_tuple[1]\n+    # POST request over network\n+    response = _post_request(base_url, body_as_string, updated_header)\n+\n+    if response.status_code != 200:","path":"mycity/mycity/utilities/arcgis_utils.py","position":104,"original_position":104,"commit_id":"4191b80916e5c62ba532f64e76d2f509f23bb27d","original_commit_id":"4191b80916e5c62ba532f64e76d2f509f23bb27d","user":{"login":"chrislreich","id":26468455,"node_id":"MDQ6VXNlcjI2NDY4NDU1","avatar_url":"https://avatars1.githubusercontent.com/u/26468455?v=4","gravatar_id":"","url":"https://api.github.com/users/chrislreich","html_url":"https://github.com/chrislreich","followers_url":"https://api.github.com/users/chrislreich/followers","following_url":"https://api.github.com/users/chrislreich/following{/other_user}","gists_url":"https://api.github.com/users/chrislreich/gists{/gist_id}","starred_url":"https://api.github.com/users/chrislreich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrislreich/subscriptions","organizations_url":"https://api.github.com/users/chrislreich/orgs","repos_url":"https://api.github.com/users/chrislreich/repos","events_url":"https://api.github.com/users/chrislreich/events{/privacy}","received_events_url":"https://api.github.com/users/chrislreich/received_events","type":"User","site_admin":false},"body":"fixed","created_at":"2018-11-27T21:51:29Z","updated_at":"2018-11-27T21:51:29Z","html_url":"https://github.com/codeforboston/voiceapp311/pull/176#discussion_r236860856","pull_request_url":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/176","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/comments/236860856"},"html":{"href":"https://github.com/codeforboston/voiceapp311/pull/176#discussion_r236860856"},"pull_request":{"href":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/176"}},"in_reply_to_id":233285296},"pull_request":{"url":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/176","id":230674329,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMwNjc0MzI5","html_url":"https://github.com/codeforboston/voiceapp311/pull/176","diff_url":"https://github.com/codeforboston/voiceapp311/pull/176.diff","patch_url":"https://github.com/codeforboston/voiceapp311/pull/176.patch","issue_url":"https://api.github.com/repos/codeforboston/voiceapp311/issues/176","number":176,"state":"open","locked":false,"title":"Google maps migration 170","user":{"login":"chrislreich","id":26468455,"node_id":"MDQ6VXNlcjI2NDY4NDU1","avatar_url":"https://avatars1.githubusercontent.com/u/26468455?v=4","gravatar_id":"","url":"https://api.github.com/users/chrislreich","html_url":"https://github.com/chrislreich","followers_url":"https://api.github.com/users/chrislreich/followers","following_url":"https://api.github.com/users/chrislreich/following{/other_user}","gists_url":"https://api.github.com/users/chrislreich/gists{/gist_id}","starred_url":"https://api.github.com/users/chrislreich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrislreich/subscriptions","organizations_url":"https://api.github.com/users/chrislreich/orgs","repos_url":"https://api.github.com/users/chrislreich/repos","events_url":"https://api.github.com/users/chrislreich/events{/privacy}","received_events_url":"https://api.github.com/users/chrislreich/received_events","type":"User","site_admin":false},"body":"Removes Google maps dependency and migrates to ArcGIS","created_at":"2018-11-14T00:44:45Z","updated_at":"2018-11-27T21:51:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[{"login":"curranjm","id":8085559,"node_id":"MDQ6VXNlcjgwODU1NTk=","avatar_url":"https://avatars3.githubusercontent.com/u/8085559?v=4","gravatar_id":"","url":"https://api.github.com/users/curranjm","html_url":"https://github.com/curranjm","followers_url":"https://api.github.com/users/curranjm/followers","following_url":"https://api.github.com/users/curranjm/following{/other_user}","gists_url":"https://api.github.com/users/curranjm/gists{/gist_id}","starred_url":"https://api.github.com/users/curranjm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/curranjm/subscriptions","organizations_url":"https://api.github.com/users/curranjm/orgs","repos_url":"https://api.github.com/users/curranjm/repos","events_url":"https://api.github.com/users/curranjm/events{/privacy}","received_events_url":"https://api.github.com/users/curranjm/received_events","type":"User","site_admin":false},{"login":"Joshhw","id":10734399,"node_id":"MDQ6VXNlcjEwNzM0Mzk5","avatar_url":"https://avatars1.githubusercontent.com/u/10734399?v=4","gravatar_id":"","url":"https://api.github.com/users/Joshhw","html_url":"https://github.com/Joshhw","followers_url":"https://api.github.com/users/Joshhw/followers","following_url":"https://api.github.com/users/Joshhw/following{/other_user}","gists_url":"https://api.github.com/users/Joshhw/gists{/gist_id}","starred_url":"https://api.github.com/users/Joshhw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Joshhw/subscriptions","organizations_url":"https://api.github.com/users/Joshhw/orgs","repos_url":"https://api.github.com/users/Joshhw/repos","events_url":"https://api.github.com/users/Joshhw/events{/privacy}","received_events_url":"https://api.github.com/users/Joshhw/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/176/commits","review_comments_url":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/176/comments","review_comment_url":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codeforboston/voiceapp311/issues/176/comments","statuses_url":"https://api.github.com/repos/codeforboston/voiceapp311/statuses/4191b80916e5c62ba532f64e76d2f509f23bb27d","head":{"label":"chrislreich:google_maps_migration_170","ref":"google_maps_migration_170","sha":"4191b80916e5c62ba532f64e76d2f509f23bb27d","user":{"login":"chrislreich","id":26468455,"node_id":"MDQ6VXNlcjI2NDY4NDU1","avatar_url":"https://avatars1.githubusercontent.com/u/26468455?v=4","gravatar_id":"","url":"https://api.github.com/users/chrislreich","html_url":"https://github.com/chrislreich","followers_url":"https://api.github.com/users/chrislreich/followers","following_url":"https://api.github.com/users/chrislreich/following{/other_user}","gists_url":"https://api.github.com/users/chrislreich/gists{/gist_id}","starred_url":"https://api.github.com/users/chrislreich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrislreich/subscriptions","organizations_url":"https://api.github.com/users/chrislreich/orgs","repos_url":"https://api.github.com/users/chrislreich/repos","events_url":"https://api.github.com/users/chrislreich/events{/privacy}","received_events_url":"https://api.github.com/users/chrislreich/received_events","type":"User","site_admin":false},"repo":{"id":140498299,"node_id":"MDEwOlJlcG9zaXRvcnkxNDA0OTgyOTk=","name":"voiceapp311","full_name":"chrislreich/voiceapp311","private":false,"owner":{"login":"chrislreich","id":26468455,"node_id":"MDQ6VXNlcjI2NDY4NDU1","avatar_url":"https://avatars1.githubusercontent.com/u/26468455?v=4","gravatar_id":"","url":"https://api.github.com/users/chrislreich","html_url":"https://github.com/chrislreich","followers_url":"https://api.github.com/users/chrislreich/followers","following_url":"https://api.github.com/users/chrislreich/following{/other_user}","gists_url":"https://api.github.com/users/chrislreich/gists{/gist_id}","starred_url":"https://api.github.com/users/chrislreich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrislreich/subscriptions","organizations_url":"https://api.github.com/users/chrislreich/orgs","repos_url":"https://api.github.com/users/chrislreich/repos","events_url":"https://api.github.com/users/chrislreich/events{/privacy}","received_events_url":"https://api.github.com/users/chrislreich/received_events","type":"User","site_admin":false},"html_url":"https://github.com/chrislreich/voiceapp311","description":"Voice assistant connection to Boston services","fork":true,"url":"https://api.github.com/repos/chrislreich/voiceapp311","forks_url":"https://api.github.com/repos/chrislreich/voiceapp311/forks","keys_url":"https://api.github.com/repos/chrislreich/voiceapp311/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chrislreich/voiceapp311/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chrislreich/voiceapp311/teams","hooks_url":"https://api.github.com/repos/chrislreich/voiceapp311/hooks","issue_events_url":"https://api.github.com/repos/chrislreich/voiceapp311/issues/events{/number}","events_url":"https://api.github.com/repos/chrislreich/voiceapp311/events","assignees_url":"https://api.github.com/repos/chrislreich/voiceapp311/assignees{/user}","branches_url":"https://api.github.com/repos/chrislreich/voiceapp311/branches{/branch}","tags_url":"https://api.github.com/repos/chrislreich/voiceapp311/tags","blobs_url":"https://api.github.com/repos/chrislreich/voiceapp311/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chrislreich/voiceapp311/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chrislreich/voiceapp311/git/refs{/sha}","trees_url":"https://api.github.com/repos/chrislreich/voiceapp311/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chrislreich/voiceapp311/statuses/{sha}","languages_url":"https://api.github.com/repos/chrislreich/voiceapp311/languages","stargazers_url":"https://api.github.com/repos/chrislreich/voiceapp311/stargazers","contributors_url":"https://api.github.com/repos/chrislreich/voiceapp311/contributors","subscribers_url":"https://api.github.com/repos/chrislreich/voiceapp311/subscribers","subscription_url":"https://api.github.com/repos/chrislreich/voiceapp311/subscription","commits_url":"https://api.github.com/repos/chrislreich/voiceapp311/commits{/sha}","git_commits_url":"https://api.github.com/repos/chrislreich/voiceapp311/git/commits{/sha}","comments_url":"https://api.github.com/repos/chrislreich/voiceapp311/comments{/number}","issue_comment_url":"https://api.github.com/repos/chrislreich/voiceapp311/issues/comments{/number}","contents_url":"https://api.github.com/repos/chrislreich/voiceapp311/contents/{+path}","compare_url":"https://api.github.com/repos/chrislreich/voiceapp311/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chrislreich/voiceapp311/merges","archive_url":"https://api.github.com/repos/chrislreich/voiceapp311/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chrislreich/voiceapp311/downloads","issues_url":"https://api.github.com/repos/chrislreich/voiceapp311/issues{/number}","pulls_url":"https://api.github.com/repos/chrislreich/voiceapp311/pulls{/number}","milestones_url":"https://api.github.com/repos/chrislreich/voiceapp311/milestones{/number}","notifications_url":"https://api.github.com/repos/chrislreich/voiceapp311/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chrislreich/voiceapp311/labels{/name}","releases_url":"https://api.github.com/repos/chrislreich/voiceapp311/releases{/id}","deployments_url":"https://api.github.com/repos/chrislreich/voiceapp311/deployments","created_at":"2018-07-10T23:39:20Z","updated_at":"2018-10-24T01:07:51Z","pushed_at":"2018-11-14T00:33:20Z","git_url":"git://github.com/chrislreich/voiceapp311.git","ssh_url":"git@github.com:chrislreich/voiceapp311.git","clone_url":"https://github.com/chrislreich/voiceapp311.git","svn_url":"https://github.com/chrislreich/voiceapp311","homepage":"","size":14059,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"codeforboston:master","ref":"master","sha":"d9a14a0d71b6f68306fc72ac95ae798b951b7747","user":{"login":"codeforboston","id":2533182,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MzMxODI=","avatar_url":"https://avatars1.githubusercontent.com/u/2533182?v=4","gravatar_id":"","url":"https://api.github.com/users/codeforboston","html_url":"https://github.com/codeforboston","followers_url":"https://api.github.com/users/codeforboston/followers","following_url":"https://api.github.com/users/codeforboston/following{/other_user}","gists_url":"https://api.github.com/users/codeforboston/gists{/gist_id}","starred_url":"https://api.github.com/users/codeforboston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codeforboston/subscriptions","organizations_url":"https://api.github.com/users/codeforboston/orgs","repos_url":"https://api.github.com/users/codeforboston/repos","events_url":"https://api.github.com/users/codeforboston/events{/privacy}","received_events_url":"https://api.github.com/users/codeforboston/received_events","type":"Organization","site_admin":false},"repo":{"id":104578381,"node_id":"MDEwOlJlcG9zaXRvcnkxMDQ1NzgzODE=","name":"voiceapp311","full_name":"codeforboston/voiceapp311","private":false,"owner":{"login":"codeforboston","id":2533182,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MzMxODI=","avatar_url":"https://avatars1.githubusercontent.com/u/2533182?v=4","gravatar_id":"","url":"https://api.github.com/users/codeforboston","html_url":"https://github.com/codeforboston","followers_url":"https://api.github.com/users/codeforboston/followers","following_url":"https://api.github.com/users/codeforboston/following{/other_user}","gists_url":"https://api.github.com/users/codeforboston/gists{/gist_id}","starred_url":"https://api.github.com/users/codeforboston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codeforboston/subscriptions","organizations_url":"https://api.github.com/users/codeforboston/orgs","repos_url":"https://api.github.com/users/codeforboston/repos","events_url":"https://api.github.com/users/codeforboston/events{/privacy}","received_events_url":"https://api.github.com/users/codeforboston/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/codeforboston/voiceapp311","description":"Voice assistant connection to Boston services","fork":false,"url":"https://api.github.com/repos/codeforboston/voiceapp311","forks_url":"https://api.github.com/repos/codeforboston/voiceapp311/forks","keys_url":"https://api.github.com/repos/codeforboston/voiceapp311/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codeforboston/voiceapp311/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codeforboston/voiceapp311/teams","hooks_url":"https://api.github.com/repos/codeforboston/voiceapp311/hooks","issue_events_url":"https://api.github.com/repos/codeforboston/voiceapp311/issues/events{/number}","events_url":"https://api.github.com/repos/codeforboston/voiceapp311/events","assignees_url":"https://api.github.com/repos/codeforboston/voiceapp311/assignees{/user}","branches_url":"https://api.github.com/repos/codeforboston/voiceapp311/branches{/branch}","tags_url":"https://api.github.com/repos/codeforboston/voiceapp311/tags","blobs_url":"https://api.github.com/repos/codeforboston/voiceapp311/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codeforboston/voiceapp311/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codeforboston/voiceapp311/git/refs{/sha}","trees_url":"https://api.github.com/repos/codeforboston/voiceapp311/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codeforboston/voiceapp311/statuses/{sha}","languages_url":"https://api.github.com/repos/codeforboston/voiceapp311/languages","stargazers_url":"https://api.github.com/repos/codeforboston/voiceapp311/stargazers","contributors_url":"https://api.github.com/repos/codeforboston/voiceapp311/contributors","subscribers_url":"https://api.github.com/repos/codeforboston/voiceapp311/subscribers","subscription_url":"https://api.github.com/repos/codeforboston/voiceapp311/subscription","commits_url":"https://api.github.com/repos/codeforboston/voiceapp311/commits{/sha}","git_commits_url":"https://api.github.com/repos/codeforboston/voiceapp311/git/commits{/sha}","comments_url":"https://api.github.com/repos/codeforboston/voiceapp311/comments{/number}","issue_comment_url":"https://api.github.com/repos/codeforboston/voiceapp311/issues/comments{/number}","contents_url":"https://api.github.com/repos/codeforboston/voiceapp311/contents/{+path}","compare_url":"https://api.github.com/repos/codeforboston/voiceapp311/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codeforboston/voiceapp311/merges","archive_url":"https://api.github.com/repos/codeforboston/voiceapp311/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codeforboston/voiceapp311/downloads","issues_url":"https://api.github.com/repos/codeforboston/voiceapp311/issues{/number}","pulls_url":"https://api.github.com/repos/codeforboston/voiceapp311/pulls{/number}","milestones_url":"https://api.github.com/repos/codeforboston/voiceapp311/milestones{/number}","notifications_url":"https://api.github.com/repos/codeforboston/voiceapp311/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codeforboston/voiceapp311/labels{/name}","releases_url":"https://api.github.com/repos/codeforboston/voiceapp311/releases{/id}","deployments_url":"https://api.github.com/repos/codeforboston/voiceapp311/deployments","created_at":"2017-09-23T15:36:56Z","updated_at":"2018-11-24T20:02:58Z","pushed_at":"2018-11-25T20:52:46Z","git_url":"git://github.com/codeforboston/voiceapp311.git","ssh_url":"git@github.com:codeforboston/voiceapp311.git","clone_url":"https://github.com/codeforboston/voiceapp311.git","svn_url":"https://github.com/codeforboston/voiceapp311","homepage":"","size":14078,"stargazers_count":17,"watchers_count":17,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"archived":false,"open_issues_count":48,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":31,"open_issues":48,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/176"},"html":{"href":"https://github.com/codeforboston/voiceapp311/pull/176"},"issue":{"href":"https://api.github.com/repos/codeforboston/voiceapp311/issues/176"},"comments":{"href":"https://api.github.com/repos/codeforboston/voiceapp311/issues/176/comments"},"review_comments":{"href":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/176/comments"},"review_comment":{"href":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codeforboston/voiceapp311/pulls/176/commits"},"statuses":{"href":"https://api.github.com/repos/codeforboston/voiceapp311/statuses/4191b80916e5c62ba532f64e76d2f509f23bb27d"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"chrislreich"}}