{"action":"created","comment":{"url":"https://api.github.com/repos/18F/tock/pulls/comments/77415247","id":77415247,"diff_hunk":"@@ -0,0 +1,153 @@\n+import requests\n+import os\n+import json\n+from datetime import datetime, timedelta\n+\n+message = '\\nResults of operation:'\n+print(message)\n+print(len(message) * '=')\n+\n+\"\"\"\n+Set up API request.\n+\"\"\"\n+url = 'https://api.floatschedule.com/api/v1/'\n+headers = {'Authorization': 'Bearer ' + os.environ.get('FLOAT_API_KEY')}\n+\n+\"\"\"\n+Fetch task data  for prior and next six months.\n+\"\"\"\n+endpoint = 'tasks'\n+target_date = datetime.today() - timedelta(weeks=26)\n+year = target_date.year\n+month = target_date.month\n+day = target_date.day\n+weeks = '52'\n+request_date = str(year) + '-' + str(month) + '-' + str(day)\n+payload = {'start_day': request_date, 'weeks': weeks}\n+r = requests.get(url + endpoint, headers=headers, params=payload)\n+task_data = json.loads(r.content.lower().strip())\n+print('\\nFetched task items from Float.')\n+\n+\"\"\"\n+Fetch people data for all users from Float.\n+\"\"\"\n+endpoint = 'people'\n+r = requests.get(url + endpoint, headers=headers)\n+people_data = json.loads(r.content.lower().strip())\n+print('\\nFetched people items from Float.')\n+\n+\"\"\"\n+Clean people data for all users from Float to remove all but req'd fields.\n+\"\"\"\n+clean_data = list()\n+q = len(people_data['people']) - 1\n+while q >= 0:\n+    clean_data.append(\n+        {'im': people_data['people'][q]['im'],\n+            'people_id': people_data['people'][q]['people_id']\n+        }\n+        )\n+    q -= 1\n+print('\\nCleaned Float people data.')\n+\n+\"\"\"\n+Pull out relevant elements from task result.\n+\"\"\"\n+task_list = list()\n+for people in task_data['people']:\n+    for tasks in people['tasks']:\n+        task_list.append(dict(tasks))\n+\n+for i in task_list:\n+    i.update({'tock_pk': None, 'im': None})\n+print('\\nCleaned Float task data.')\n+\n+\"\"\"\n+Fetch Tock Data\n+\"\"\"\n+r = requests.get('https://tock-app.18f.gov/api/users.json')\n+output = json.loads(r.content)\n+print('\\nTock data fetched.')\n+\n+\"\"\"\n+Build crosswalk.\n+\"\"\"\n+v = len(output['results']) - 1\n+crosswalk = list()\n+while v >= 0:\n+    crosswalk.append(\n+        {'username': output['results'][v]['username'],\n+        'pk': output['results'][v]['id']\n+        }\n+        )\n+    v -= 1\n+\n+a = len(crosswalk) - 1\n+b = len(clean_data) - 1\n+while a >= 0:\n+    while b >= 0:\n+        tock_record = str(crosswalk[a]['username'])\n+        float_record = str(clean_data[b]['im'])\n+        if tock_record[0:12] == float_record[0:12]:\n+            crosswalk[a].update({\n+                'people_id': clean_data[b]['people_id'],\n+                'im': clean_data[b]['im'],\n+                }\n+                )\n+        b -= 1\n+    a -= 1\n+    b = len(clean_data) - 1\n+print('\\nFloat / Tock crosswalk built.')\n+\n+clean_crosswalk = list()\n+for i in crosswalk:\n+    if len(i)>3:\n+        clean_crosswalk.append(i)\n+\n+x = len(clean_crosswalk)\n+print('\\nFound %s matches between Float \"im\" values and Tock \"username\" '\n+    'values.\\nAvailable Tock User pk values will be assigned to Float task '\n+    'data.') % (x)\n+\n+\"\"\"\n+Load values from crosswalk.\n+\"\"\"\n+b = len(clean_crosswalk) - 1\n+e = len(task_list) - 1\n+count = 0\n+while b >= 0:\n+    while e >= 0:\n+        if clean_crosswalk[b]['people_id'] == task_list[e]['people_id']:\n+            task_list[e].update(\n+                {'tock_pk': clean_crosswalk[b]['pk'], 'im': clean_crosswalk[b]['im']})\n+            count += 1\n+        e -=1\n+\n+    b -= 1\n+    e = len(task_list) - 1\n+print('\\nMatches from crosswalk loaded into Float task data.')\n+\n+\"\"\"\n+Write elements to new dictionary that matches Django's loaddata fixture req's.\n+\"\"\"\n+fixture = list()\n+for item in task_list:\n+    fixture.append(dict())\n+y = len(task_list)\n+x = y - 1\n+while x >= 0:\n+    fixture[x][\"pk\"] = x\n+    fixture[x][\"model\"] = \"float.floattasks\"\n+    fixture[x][\"fields\"] = task_list[x]\n+    x = x - 1","path":"float_data_for_tock.py","position":142,"original_position":142,"commit_id":"e37b15ac7e36cdb03321c4e3b4718c1aedf17f1c","original_commit_id":"e37b15ac7e36cdb03321c4e3b4718c1aedf17f1c","user":{"login":"cmc333333","id":326918,"avatar_url":"https://avatars.githubusercontent.com/u/326918?v=3","gravatar_id":"","url":"https://api.github.com/users/cmc333333","html_url":"https://github.com/cmc333333","followers_url":"https://api.github.com/users/cmc333333/followers","following_url":"https://api.github.com/users/cmc333333/following{/other_user}","gists_url":"https://api.github.com/users/cmc333333/gists{/gist_id}","starred_url":"https://api.github.com/users/cmc333333/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmc333333/subscriptions","organizations_url":"https://api.github.com/users/cmc333333/orgs","repos_url":"https://api.github.com/users/cmc333333/repos","events_url":"https://api.github.com/users/cmc333333/events{/privacy}","received_events_url":"https://api.github.com/users/cmc333333/received_events","type":"User","site_admin":false},"body":"Quick note that while loops are generally frowned on in Python code. Have you seen [`range`](https://docs.python.org/2/library/functions.html#range)?\r\n\r\nAs order doesn't matter here, the equivalent loop would be\r\n```python\r\nfor x in range(y):\r\n    fixture[x][\"pk\"] = x\r\n    fixture[x][\"model\"] = \"float.floattasks\"\r\n    fixture[x][\"fields\"] = task_list[x]\r\n```\r\n\r\n\r\nWe can do better, though: you can simplify lines 133 through 142 to something like\r\n```python\r\nfixture = []\r\nfor idx, task in enumerate(task_list):\r\n    fixture.append({'pk': idx,\r\n                    'model': 'float.floattasks',\r\n                    'fields': task})\r\n```","created_at":"2016-09-02T21:37:20Z","updated_at":"2016-09-02T21:37:20Z","html_url":"https://github.com/18F/tock/pull/389#discussion_r77415247","pull_request_url":"https://api.github.com/repos/18F/tock/pulls/389","_links":{"self":{"href":"https://api.github.com/repos/18F/tock/pulls/comments/77415247"},"html":{"href":"https://github.com/18F/tock/pull/389#discussion_r77415247"},"pull_request":{"href":"https://api.github.com/repos/18F/tock/pulls/389"}}},"pull_request":{"url":"https://api.github.com/repos/18F/tock/pulls/389","id":75862334,"html_url":"https://github.com/18F/tock/pull/389","diff_url":"https://github.com/18F/tock/pull/389.diff","patch_url":"https://github.com/18F/tock/pull/389.patch","issue_url":"https://api.github.com/repos/18F/tock/issues/389","number":389,"state":"open","locked":false,"title":"[WIP] create float app, model and load float data","user":{"login":"batemapf","id":7645362,"avatar_url":"https://avatars.githubusercontent.com/u/7645362?v=3","gravatar_id":"","url":"https://api.github.com/users/batemapf","html_url":"https://github.com/batemapf","followers_url":"https://api.github.com/users/batemapf/followers","following_url":"https://api.github.com/users/batemapf/following{/other_user}","gists_url":"https://api.github.com/users/batemapf/gists{/gist_id}","starred_url":"https://api.github.com/users/batemapf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/batemapf/subscriptions","organizations_url":"https://api.github.com/users/batemapf/orgs","repos_url":"https://api.github.com/users/batemapf/repos","events_url":"https://api.github.com/users/batemapf/events{/privacy}","received_events_url":"https://api.github.com/users/batemapf/received_events","type":"User","site_admin":false},"body":"- create a new app in the tock project that will house task data from Float\r\n- populate `models.py` with matching fields from [here](https://github.com/floatschedule/api/blob/master/Sections/tasks.md) ","created_at":"2016-06-30T17:53:04Z","updated_at":"2016-09-02T21:37:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"13ccc6081924869995064ac894c7fc24ff879484","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/18F/tock/pulls/389/commits","review_comments_url":"https://api.github.com/repos/18F/tock/pulls/389/comments","review_comment_url":"https://api.github.com/repos/18F/tock/pulls/comments{/number}","comments_url":"https://api.github.com/repos/18F/tock/issues/389/comments","statuses_url":"https://api.github.com/repos/18F/tock/statuses/e37b15ac7e36cdb03321c4e3b4718c1aedf17f1c","head":{"label":"18F:add-float-app","ref":"add-float-app","sha":"e37b15ac7e36cdb03321c4e3b4718c1aedf17f1c","user":{"login":"18F","id":6233994,"avatar_url":"https://avatars.githubusercontent.com/u/6233994?v=3","gravatar_id":"","url":"https://api.github.com/users/18F","html_url":"https://github.com/18F","followers_url":"https://api.github.com/users/18F/followers","following_url":"https://api.github.com/users/18F/following{/other_user}","gists_url":"https://api.github.com/users/18F/gists{/gist_id}","starred_url":"https://api.github.com/users/18F/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/18F/subscriptions","organizations_url":"https://api.github.com/users/18F/orgs","repos_url":"https://api.github.com/users/18F/repos","events_url":"https://api.github.com/users/18F/events{/privacy}","received_events_url":"https://api.github.com/users/18F/received_events","type":"Organization","site_admin":false},"repo":{"id":30162008,"name":"tock","full_name":"18F/tock","owner":{"login":"18F","id":6233994,"avatar_url":"https://avatars.githubusercontent.com/u/6233994?v=3","gravatar_id":"","url":"https://api.github.com/users/18F","html_url":"https://github.com/18F","followers_url":"https://api.github.com/users/18F/followers","following_url":"https://api.github.com/users/18F/following{/other_user}","gists_url":"https://api.github.com/users/18F/gists{/gist_id}","starred_url":"https://api.github.com/users/18F/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/18F/subscriptions","organizations_url":"https://api.github.com/users/18F/orgs","repos_url":"https://api.github.com/users/18F/repos","events_url":"https://api.github.com/users/18F/events{/privacy}","received_events_url":"https://api.github.com/users/18F/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/18F/tock","description":"A simple time tracking experiment","fork":false,"url":"https://api.github.com/repos/18F/tock","forks_url":"https://api.github.com/repos/18F/tock/forks","keys_url":"https://api.github.com/repos/18F/tock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/18F/tock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/18F/tock/teams","hooks_url":"https://api.github.com/repos/18F/tock/hooks","issue_events_url":"https://api.github.com/repos/18F/tock/issues/events{/number}","events_url":"https://api.github.com/repos/18F/tock/events","assignees_url":"https://api.github.com/repos/18F/tock/assignees{/user}","branches_url":"https://api.github.com/repos/18F/tock/branches{/branch}","tags_url":"https://api.github.com/repos/18F/tock/tags","blobs_url":"https://api.github.com/repos/18F/tock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/18F/tock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/18F/tock/git/refs{/sha}","trees_url":"https://api.github.com/repos/18F/tock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/18F/tock/statuses/{sha}","languages_url":"https://api.github.com/repos/18F/tock/languages","stargazers_url":"https://api.github.com/repos/18F/tock/stargazers","contributors_url":"https://api.github.com/repos/18F/tock/contributors","subscribers_url":"https://api.github.com/repos/18F/tock/subscribers","subscription_url":"https://api.github.com/repos/18F/tock/subscription","commits_url":"https://api.github.com/repos/18F/tock/commits{/sha}","git_commits_url":"https://api.github.com/repos/18F/tock/git/commits{/sha}","comments_url":"https://api.github.com/repos/18F/tock/comments{/number}","issue_comment_url":"https://api.github.com/repos/18F/tock/issues/comments{/number}","contents_url":"https://api.github.com/repos/18F/tock/contents/{+path}","compare_url":"https://api.github.com/repos/18F/tock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/18F/tock/merges","archive_url":"https://api.github.com/repos/18F/tock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/18F/tock/downloads","issues_url":"https://api.github.com/repos/18F/tock/issues{/number}","pulls_url":"https://api.github.com/repos/18F/tock/pulls{/number}","milestones_url":"https://api.github.com/repos/18F/tock/milestones{/number}","notifications_url":"https://api.github.com/repos/18F/tock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/18F/tock/labels{/name}","releases_url":"https://api.github.com/repos/18F/tock/releases{/id}","deployments_url":"https://api.github.com/repos/18F/tock/deployments","created_at":"2015-02-01T22:19:32Z","updated_at":"2016-08-15T18:22:17Z","pushed_at":"2016-09-02T21:16:41Z","git_url":"git://github.com/18F/tock.git","ssh_url":"git@github.com:18F/tock.git","clone_url":"https://github.com/18F/tock.git","svn_url":"https://github.com/18F/tock","homepage":"https://18f.gsa.gov/2015/05/21/TockingTime/","size":1977,"stargazers_count":81,"watchers_count":81,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":37,"forks":26,"open_issues":37,"watchers":81,"default_branch":"master"}},"base":{"label":"18F:master","ref":"master","sha":"4e76eae1b19dcff6149f4173e8ea4b36f33a48a4","user":{"login":"18F","id":6233994,"avatar_url":"https://avatars.githubusercontent.com/u/6233994?v=3","gravatar_id":"","url":"https://api.github.com/users/18F","html_url":"https://github.com/18F","followers_url":"https://api.github.com/users/18F/followers","following_url":"https://api.github.com/users/18F/following{/other_user}","gists_url":"https://api.github.com/users/18F/gists{/gist_id}","starred_url":"https://api.github.com/users/18F/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/18F/subscriptions","organizations_url":"https://api.github.com/users/18F/orgs","repos_url":"https://api.github.com/users/18F/repos","events_url":"https://api.github.com/users/18F/events{/privacy}","received_events_url":"https://api.github.com/users/18F/received_events","type":"Organization","site_admin":false},"repo":{"id":30162008,"name":"tock","full_name":"18F/tock","owner":{"login":"18F","id":6233994,"avatar_url":"https://avatars.githubusercontent.com/u/6233994?v=3","gravatar_id":"","url":"https://api.github.com/users/18F","html_url":"https://github.com/18F","followers_url":"https://api.github.com/users/18F/followers","following_url":"https://api.github.com/users/18F/following{/other_user}","gists_url":"https://api.github.com/users/18F/gists{/gist_id}","starred_url":"https://api.github.com/users/18F/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/18F/subscriptions","organizations_url":"https://api.github.com/users/18F/orgs","repos_url":"https://api.github.com/users/18F/repos","events_url":"https://api.github.com/users/18F/events{/privacy}","received_events_url":"https://api.github.com/users/18F/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/18F/tock","description":"A simple time tracking experiment","fork":false,"url":"https://api.github.com/repos/18F/tock","forks_url":"https://api.github.com/repos/18F/tock/forks","keys_url":"https://api.github.com/repos/18F/tock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/18F/tock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/18F/tock/teams","hooks_url":"https://api.github.com/repos/18F/tock/hooks","issue_events_url":"https://api.github.com/repos/18F/tock/issues/events{/number}","events_url":"https://api.github.com/repos/18F/tock/events","assignees_url":"https://api.github.com/repos/18F/tock/assignees{/user}","branches_url":"https://api.github.com/repos/18F/tock/branches{/branch}","tags_url":"https://api.github.com/repos/18F/tock/tags","blobs_url":"https://api.github.com/repos/18F/tock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/18F/tock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/18F/tock/git/refs{/sha}","trees_url":"https://api.github.com/repos/18F/tock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/18F/tock/statuses/{sha}","languages_url":"https://api.github.com/repos/18F/tock/languages","stargazers_url":"https://api.github.com/repos/18F/tock/stargazers","contributors_url":"https://api.github.com/repos/18F/tock/contributors","subscribers_url":"https://api.github.com/repos/18F/tock/subscribers","subscription_url":"https://api.github.com/repos/18F/tock/subscription","commits_url":"https://api.github.com/repos/18F/tock/commits{/sha}","git_commits_url":"https://api.github.com/repos/18F/tock/git/commits{/sha}","comments_url":"https://api.github.com/repos/18F/tock/comments{/number}","issue_comment_url":"https://api.github.com/repos/18F/tock/issues/comments{/number}","contents_url":"https://api.github.com/repos/18F/tock/contents/{+path}","compare_url":"https://api.github.com/repos/18F/tock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/18F/tock/merges","archive_url":"https://api.github.com/repos/18F/tock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/18F/tock/downloads","issues_url":"https://api.github.com/repos/18F/tock/issues{/number}","pulls_url":"https://api.github.com/repos/18F/tock/pulls{/number}","milestones_url":"https://api.github.com/repos/18F/tock/milestones{/number}","notifications_url":"https://api.github.com/repos/18F/tock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/18F/tock/labels{/name}","releases_url":"https://api.github.com/repos/18F/tock/releases{/id}","deployments_url":"https://api.github.com/repos/18F/tock/deployments","created_at":"2015-02-01T22:19:32Z","updated_at":"2016-08-15T18:22:17Z","pushed_at":"2016-09-02T21:16:41Z","git_url":"git://github.com/18F/tock.git","ssh_url":"git@github.com:18F/tock.git","clone_url":"https://github.com/18F/tock.git","svn_url":"https://github.com/18F/tock","homepage":"https://18f.gsa.gov/2015/05/21/TockingTime/","size":1977,"stargazers_count":81,"watchers_count":81,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":37,"forks":26,"open_issues":37,"watchers":81,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/18F/tock/pulls/389"},"html":{"href":"https://github.com/18F/tock/pull/389"},"issue":{"href":"https://api.github.com/repos/18F/tock/issues/389"},"comments":{"href":"https://api.github.com/repos/18F/tock/issues/389/comments"},"review_comments":{"href":"https://api.github.com/repos/18F/tock/pulls/389/comments"},"review_comment":{"href":"https://api.github.com/repos/18F/tock/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/18F/tock/pulls/389/commits"},"statuses":{"href":"https://api.github.com/repos/18F/tock/statuses/e37b15ac7e36cdb03321c4e3b4718c1aedf17f1c"}}}}
{"actor":{"display_login":"cmc333333"}}