#!/bin/env tclsh # script to convert the spdx db to a dict package require http package require json package require tls tls::init -autoservername true http::register https 443 ::tls::socket set dump_path [dict get [info frame [info frame]] file] set dump_path [file dirname $dump_path] set dump_path [file join $dump_path dump.tcldict.gz] puts "will save to $dump_path" set tok [http::geturl "https://spdx.org/licenses/licenses.json"] if {[http::ncode $tok] != 200} { puts stderr "got [http::code $tok] downloading index: [http::data $tok]" exit -1 } set licenses [json::json2dict [http::data $tok]] unset $tok set licenses [dict get $licenses licenses] set dump {} set lcount [llength $licenses] puts "downloading $lcount licenses" set progress 0 foreach license $licenses { set tok [http::geturl [dict get $license detailsUrl]] if {[http::ncode $tok] != 200} { puts stderr "got [http::code $tok] downloading license [dict get $license licenseId]: [http::data $tok]" exit -2 } set details [json::json2dict [http::data $tok]] unset $tok dict set dump [dict get $license licenseId] \ [list name [dict get $license name] \ spdx_uri [dict get $license reference] \ see_also [dict get $license seeAlso] \ text [dict get $details licenseText]] incr progress puts -nonewline "downloaded $progress / $lcount\r" flush stdout } puts "downloaded $lcount licenses" set dumpfd [open $dump_path w] zlib push gzip $dumpfd -level 9 puts $dumpfd $dump flush $dumpfd close $dumpfd puts "saved to $dump_path"