pull: Add licenses-full.json with all the information
authorW. Trevor King <wking@tremily.us>
Sat, 11 Nov 2017 21:20:33 +0000 (13:20 -0800)
committerW. Trevor King <wking@tremily.us>
Sat, 11 Nov 2017 21:39:20 +0000 (13:39 -0800)
I prefer the minimal index (as I explain in the previous commit), but
some consumers need details on multiple licenses and prefer to collect
data with a single network request.  Even with all the data in one
endpoint, I don't expect this to grow to a point where it would be
expensive to serve.  And at the moment, GitHub is donating the server
bandwidth anyway.

Also add anchors to the README so folks can link to the docs for a
specific endpoint.  We need to use the explicit closing tag (vs.
<a name="..." />) to get GitHub to render Markdown in the remainer of
the license-list paragraphs.

README.md
pull.py

index 0cdc83ae1e87403b25ffc7dfec00c6fe5109263b..4112b3026511f072380b63d6ff8480e9cb85b246 100644 (file)
--- a/README.md
+++ b/README.md
@@ -9,17 +9,23 @@ Ideally we'll hand this repository over to the FSF once they're ready to maintai
 
 ## Endpoints
 
-You can pull the set of identifiers from [https://wking.github.io/fsf-api/licenses.json](https://wking.github.io/fsf-api/licenses.json).
+<a name="licenses.json"></a>
+You can pull an array of identifiers from [https://wking.github.io/fsf-api/licenses.json](https://wking.github.io/fsf-api/licenses.json).
+
+<a name="licenses-full.json"></a>
+You can pull an object with all the license data [https://wking.github.io/fsf-api/licenses-full.json](https://wking.github.io/fsf-api/licenses-full.json).
 
 You can pull an individual license from a few places:
 
-* Using their FSF ID:
+* <a name="by-fsf-id"></a>
+    Using their FSF ID:
 
         https://wking.github.io/fsf-api/{id}.json
 
     For example [https://wking.github.io/fsf-api/Expat.json](https://wking.github.io/fsf-api/Expat.json).
 
-* Using a non-FSF ID, according to the mapping between other scheme and the FSF scheme asserted by this API:
+* <a name="by-non-fsf-id"></a>
+    Using a non-FSF ID, according to the mapping between other scheme and the FSF scheme asserted by this API:
 
         https://wking.github.io/fsf-api/{scheme}/{id}.json
 
diff --git a/pull.py b/pull.py
index 7ad74fef2496217065c5df7833413a510abc2059..293e2cee0cd1d6d1fff10ddbd3b2dfc732278e5f 100755 (executable)
--- a/pull.py
+++ b/pull.py
@@ -172,10 +172,12 @@ def save(licenses, dir=os.curdir):
     with open(os.path.join(dir, 'licenses.json'), 'w') as f:
         json.dump(obj=index, fp=f, indent=2)
         f.write('\n')
+    full_index = {}
     for id, license in licenses.items():
         license = license.copy()
         if 'tags' in license:
             license['tags'] = sorted(license['tags'])
+        full_index[id] = license
         license_path = os.path.join(dir, '{}.json'.format(id))
         with open(license_path, 'w') as f:
             json.dump(obj=license, fp=f, indent=2, sort_keys=True)
@@ -185,6 +187,9 @@ def save(licenses, dir=os.curdir):
             os.makedirs(scheme_dir, exist_ok=True)
             id_path = os.path.join(scheme_dir, '{}.json'.format(identifier))
             os.link(license_path, id_path)
+    with open(os.path.join(dir, 'licenses-full.json'), 'w') as f:
+        json.dump(obj=full_index, fp=f, indent=2, sort_keys=True)
+        f.write('\n')
 
 
 if __name__ == '__main__':