Last active
April 3, 2019 17:58
-
-
Save shivanshuraj1333/b1252e7d835a7d147c59d1e28d8423a8 to your computer and use it in GitHub Desktop.
Script to update latest lic. version data from https://github.com/spdx/license-list-data/releases 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 requests | |
def Sort(sub_li): | |
sub_li.sort(key = lambda x: x[0]) | |
return sub_li | |
csv_data = [] | |
url = 'https://api.github.com/repos/spdx/license-list-data/releases/latest' | |
#get latest version release info in form of tag | |
tag=requests.get(url).json()['tag_name'] | |
#generate destination URL | |
fetch_url='https://raw.githubusercontent.com/spdx/license-list-data/'+tag+'/json/licenses.json' | |
jsonRes=requests.get(fetch_url).json()["licenses"] | |
for i in range(len(jsonRes)): | |
full_name = jsonRes[i]['name'] | |
identifier = jsonRes[i]['licenseId'] | |
fsf_free_libre=False | |
if 'isFsfLibre' in jsonRes[i]: | |
fsf_free_libre=True | |
osi_approved=False | |
if(jsonRes[i]['isOsiApproved']): | |
osi_approved=True | |
license_category = '' | |
text_url=jsonRes[i]['detailsUrl'] | |
license_text = requests.get(text_url).json()['licenseText'] | |
print("lic population: "+ str(int(i/len(jsonRes)*100))+"%"+" completed.", end='\r') | |
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