{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/entity-manager/pulls/comments/23301641","id":23301641,"diff_hunk":"@@ -0,0 +1,35 @@\n+#!/usr/bin/env python\n+\n+import csv\n+import json\n+import os\n+import sys\n+\n+\n+def format_entities_as_list(entities):\n+    for i, entity in enumerate(entities, 1):\n+        yield (unicode(i), json.dumps(entity[\"terms\"]))\n+\n+\n+def generate_entities(fobj):\n+    termsets_seen = set()\n+    for line in fobj:\n+        entity = json.loads(line)\n+        termset = tuple(entity[\"terms\"])\n+        if termset not in termsets_seen:\n+            termsets_seen.add(termset)\n+            yield entity\n+\n+\n+def load_entities_from_file(infile, outfile):\n+    if os.path.exists(outfile):\n+        raise RuntimeError(\"Output file %r already exists\" % outfile)\n+    with open(infile) as in_fobj:\n+        with open(outfile, \"wb\") as out_fobj:\n+            writer = csv.writer(out_fobj)\n+            for row in format_entities_as_list(generate_entities(in_fobj)):\n+                writer.writerow(row)\n+\n+\n+if __name__ == '__main__':\n+    load_entities_from_file(sys.argv[1], sys.argv[2])","path":"make_ids.py","position":35,"original_position":35,"commit_id":"fa3850a8423686a10d709b06905a4814268a32fb","original_commit_id":"fa3850a8423686a10d709b06905a4814268a32fb","user":{"login":"fatbusinessman","id":32775,"avatar_url":"https://avatars.githubusercontent.com/u/32775?v=3","gravatar_id":"","url":"https://api.github.com/users/fatbusinessman","html_url":"https://github.com/fatbusinessman","followers_url":"https://api.github.com/users/fatbusinessman/followers","following_url":"https://api.github.com/users/fatbusinessman/following{/other_user}","gists_url":"https://api.github.com/users/fatbusinessman/gists{/gist_id}","starred_url":"https://api.github.com/users/fatbusinessman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatbusinessman/subscriptions","organizations_url":"https://api.github.com/users/fatbusinessman/orgs","repos_url":"https://api.github.com/users/fatbusinessman/repos","events_url":"https://api.github.com/users/fatbusinessman/events{/privacy}","received_events_url":"https://api.github.com/users/fatbusinessman/received_events","type":"User","site_admin":false},"body":"Since this script is using command-line arguments for filenames anyway, and so doesn’t need any filename logic, would it be reasonable for it to read from `stdin` and write to `stdout`, to make it more Unix-friendly?","created_at":"2015-01-21T14:22:22Z","updated_at":"2015-01-21T14:22:22Z","html_url":"https://github.com/alphagov/entity-manager/pull/1#discussion_r23301641","pull_request_url":"https://api.github.com/repos/alphagov/entity-manager/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/alphagov/entity-manager/pulls/comments/23301641"},"html":{"href":"https://github.com/alphagov/entity-manager/pull/1#discussion_r23301641"},"pull_request":{"href":"https://api.github.com/repos/alphagov/entity-manager/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/entity-manager/pulls/1","id":27760999,"html_url":"https://github.com/alphagov/entity-manager/pull/1","diff_url":"https://github.com/alphagov/entity-manager/pull/1.diff","patch_url":"https://github.com/alphagov/entity-manager/pull/1.patch","issue_url":"https://api.github.com/repos/alphagov/entity-manager/issues/1","number":1,"state":"open","locked":false,"title":"Basic script to produce CSV entity data","user":{"login":"rboulton","id":73564,"avatar_url":"https://avatars.githubusercontent.com/u/73564?v=3","gravatar_id":"","url":"https://api.github.com/users/rboulton","html_url":"https://github.com/rboulton","followers_url":"https://api.github.com/users/rboulton/followers","following_url":"https://api.github.com/users/rboulton/following{/other_user}","gists_url":"https://api.github.com/users/rboulton/gists{/gist_id}","starred_url":"https://api.github.com/users/rboulton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rboulton/subscriptions","organizations_url":"https://api.github.com/users/rboulton/orgs","repos_url":"https://api.github.com/users/rboulton/repos","events_url":"https://api.github.com/users/rboulton/events{/privacy}","received_events_url":"https://api.github.com/users/rboulton/received_events","type":"User","site_admin":false},"body":"This script takes the output of the `script/export_abbreviation_entities` script in whitehall, de-dupes the entities in it, assigns IDs, and outputs the result in CSV format.","created_at":"2015-01-21T13:59:59Z","updated_at":"2015-01-21T14:22:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c5f77bf4e6a818046726fea1960785fc4365023d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/entity-manager/pulls/1/commits","review_comments_url":"https://api.github.com/repos/alphagov/entity-manager/pulls/1/comments","review_comment_url":"https://api.github.com/repos/alphagov/entity-manager/pulls/comments/{number}","comments_url":"https://api.github.com/repos/alphagov/entity-manager/issues/1/comments","statuses_url":"https://api.github.com/repos/alphagov/entity-manager/statuses/fa3850a8423686a10d709b06905a4814268a32fb","head":{"label":"alphagov:basic-script-to-make-ids","ref":"basic-script-to-make-ids","sha":"fa3850a8423686a10d709b06905a4814268a32fb","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":29475236,"name":"entity-manager","full_name":"alphagov/entity-manager","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/entity-manager","description":"Combine named entities from multiple sources and assign identifiers to them","fork":false,"url":"https://api.github.com/repos/alphagov/entity-manager","forks_url":"https://api.github.com/repos/alphagov/entity-manager/forks","keys_url":"https://api.github.com/repos/alphagov/entity-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/entity-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/entity-manager/teams","hooks_url":"https://api.github.com/repos/alphagov/entity-manager/hooks","issue_events_url":"https://api.github.com/repos/alphagov/entity-manager/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/entity-manager/events","assignees_url":"https://api.github.com/repos/alphagov/entity-manager/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/entity-manager/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/entity-manager/tags","blobs_url":"https://api.github.com/repos/alphagov/entity-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/entity-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/entity-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/entity-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/entity-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/entity-manager/languages","stargazers_url":"https://api.github.com/repos/alphagov/entity-manager/stargazers","contributors_url":"https://api.github.com/repos/alphagov/entity-manager/contributors","subscribers_url":"https://api.github.com/repos/alphagov/entity-manager/subscribers","subscription_url":"https://api.github.com/repos/alphagov/entity-manager/subscription","commits_url":"https://api.github.com/repos/alphagov/entity-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/entity-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/entity-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/entity-manager/issues/comments/{number}","contents_url":"https://api.github.com/repos/alphagov/entity-manager/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/entity-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/entity-manager/merges","archive_url":"https://api.github.com/repos/alphagov/entity-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/entity-manager/downloads","issues_url":"https://api.github.com/repos/alphagov/entity-manager/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/entity-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/entity-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/entity-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/entity-manager/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/entity-manager/releases{/id}","created_at":"2015-01-19T14:43:35Z","updated_at":"2015-01-19T14:43:35Z","pushed_at":"2015-01-21T13:59:47Z","git_url":"git://github.com/alphagov/entity-manager.git","ssh_url":"git@github.com:alphagov/entity-manager.git","clone_url":"https://github.com/alphagov/entity-manager.git","svn_url":"https://github.com/alphagov/entity-manager","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"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":"alphagov:master","ref":"master","sha":"375f24e7412d8013d23059be27a6d590e1f71f6b","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":29475236,"name":"entity-manager","full_name":"alphagov/entity-manager","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/entity-manager","description":"Combine named entities from multiple sources and assign identifiers to them","fork":false,"url":"https://api.github.com/repos/alphagov/entity-manager","forks_url":"https://api.github.com/repos/alphagov/entity-manager/forks","keys_url":"https://api.github.com/repos/alphagov/entity-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/entity-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/entity-manager/teams","hooks_url":"https://api.github.com/repos/alphagov/entity-manager/hooks","issue_events_url":"https://api.github.com/repos/alphagov/entity-manager/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/entity-manager/events","assignees_url":"https://api.github.com/repos/alphagov/entity-manager/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/entity-manager/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/entity-manager/tags","blobs_url":"https://api.github.com/repos/alphagov/entity-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/entity-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/entity-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/entity-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/entity-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/entity-manager/languages","stargazers_url":"https://api.github.com/repos/alphagov/entity-manager/stargazers","contributors_url":"https://api.github.com/repos/alphagov/entity-manager/contributors","subscribers_url":"https://api.github.com/repos/alphagov/entity-manager/subscribers","subscription_url":"https://api.github.com/repos/alphagov/entity-manager/subscription","commits_url":"https://api.github.com/repos/alphagov/entity-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/entity-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/entity-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/entity-manager/issues/comments/{number}","contents_url":"https://api.github.com/repos/alphagov/entity-manager/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/entity-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/entity-manager/merges","archive_url":"https://api.github.com/repos/alphagov/entity-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/entity-manager/downloads","issues_url":"https://api.github.com/repos/alphagov/entity-manager/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/entity-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/entity-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/entity-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/entity-manager/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/entity-manager/releases{/id}","created_at":"2015-01-19T14:43:35Z","updated_at":"2015-01-19T14:43:35Z","pushed_at":"2015-01-21T13:59:47Z","git_url":"git://github.com/alphagov/entity-manager.git","ssh_url":"git@github.com:alphagov/entity-manager.git","clone_url":"https://github.com/alphagov/entity-manager.git","svn_url":"https://github.com/alphagov/entity-manager","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"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/alphagov/entity-manager/pulls/1"},"html":{"href":"https://github.com/alphagov/entity-manager/pull/1"},"issue":{"href":"https://api.github.com/repos/alphagov/entity-manager/issues/1"},"comments":{"href":"https://api.github.com/repos/alphagov/entity-manager/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/entity-manager/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/entity-manager/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/alphagov/entity-manager/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/entity-manager/statuses/fa3850a8423686a10d709b06905a4814268a32fb"}}}}