Created
March 30, 2019 23:44
-
-
Save shivanshuraj1333/351a4c29170ecdd72d5b93ae78190038 to your computer and use it in GitHub Desktop.
Script to update dump data from https://github.com/spdx/license-list-data into a csv file to populate data base.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, csv | |
import os | |
def Sort(sub_li): | |
sub_li.sort(key = lambda x: x[0]) | |
return sub_li | |
files = next(os.walk("./license-list-data/json/details"))[2] | |
lic_dir = 'license-list-data/json/details' | |
csv_data = [] | |
for f in files : | |
path = os.path.join(os.getcwd(), os.path.join( | |
lic_dir, f)) | |
data = [] | |
with open(path, 'r', encoding='utf-8') as input_file: | |
read_json = json.load(input_file) | |
# print(read_json['isDeprecatedLicenseId']) | |
if(read_json['isDeprecatedLicenseId']==False): | |
full_name = read_json['name'] | |
identifier = read_json['licenseId'] | |
# print(path) | |
fsf_free_libre="" | |
if 'isFsfLibre' in read_json: | |
fsf_free_libre="FSF Libre" | |
else: | |
fsf_free_libre="NON-FSF Libre" | |
osi_approved="NON-OSI Approved" | |
if(read_json['isOsiApproved']): | |
osi_approved="OSI Approved" | |
license_category = '' | |
license_text = read_json['licenseText'] | |
data = [full_name, identifier, fsf_free_libre, osi_approved, license_category,license_text] | |
csv_data.append(data) | |
Sort(csv_data) | |
with open('license-info.csv', 'w') as file: | |
writer = csv.writer(file) | |
writer.writerows(csv_data) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment