Skip to content

Commit

Permalink
fix identation
Browse files Browse the repository at this point in the history
  • Loading branch information
dagonzalezfo committed Jan 30, 2024
1 parent 8db14fe commit 4d674a2
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions licenses/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,87 +17,87 @@
args=parser.parse_args()

def github(source):
"""
Function that gets spdx_id from github using his API
"""
repo=source.removeprefix('github:')
url="https://api.github.com/repos/"+repo+"/license"
headers = {
"Accept": "application/vnd.github+json",
"Authorization" : "Bearer TOKEN",
"X-GitHub-Api-Version": "2022-11-28",
}
r=requests.get(url, headers=headers)
if r.status_code != 200:
return "not found"
else:
return(r.json()['license']['spdx_id'])
"""
Function that gets spdx_id from github using his API
"""
repo=source.removeprefix('github:')
url="https://api.github.com/repos/"+repo+"/license"
headers = {
"Accept": "application/vnd.github+json",
"Authorization" : "Bearer TOKEN",
"X-GitHub-Api-Version": "2022-11-28",
}
r=requests.get(url, headers=headers)
if r.status_code != 200:
return "not found"
else:
return(r.json()['license']['spdx_id'])

def pypi(project):
"""
Function that retrives licence from PiPy
"""
url = "https://pypi.org/pypi/"
r = requests.get(url + project + "/json").json()
if r.status_code != 200:
return "not found"
else:
return(r['info']['license'])
"""
Function that retrives licence from PiPy
"""
url = "https://pypi.org/pypi/"
r = requests.get(url + project + "/json").json()
if r.status_code != 200:
return "not found"
else:
return(r['info']['license'])

def cran(project):
"""
Function that retrieves licence from CRAN
"""
Function that retrieves licence from CRAN
"""
url = "http://crandb.r-pkg.org/"
r = requests.get(url + project).json()
if r.status_code != 200:
return "not found"
else:
return(r['License'])
if r.status_code != 200:
return "not found"
else:
return(r['License'])

def repology(project):
url="https://repology.org//api/v1/"
r = requests.get(url + project).json()
if r.status_code != 200:
return "not found"
else:
return(r['License'])
if r.status_code != 200:
return "not found"
else:
return(r['License'])

def licenseInfo(project):
"""
Function that create the project info
"""
if args.source=='pypi':
lic=pypi(project)
elif "github" in args.source:
lic=github(args.source)
elif args.spdx:
lic=args.spdx
info=[("license",lic), ("source",args.source)]
return info
"""
Function that create the project info
"""
if args.source=='pypi':
lic=pypi(project)
elif "github" in args.source:
lic=github(args.source)
elif args.spdx:
lic=args.spdx
info=[("license",lic), ("source",args.source)]
return info

def updateJson(project,info):
"""
Function that updates json file
"""
with open('licenses.json','r') as licDict:
licenses=json.loads(licDict.read())
if project in licenses.keys():
print('project in licenses.json')
else:
print('we do not have the license, adding into licenses.json')
licenses[project]=dict(info)
licJson=json.dumps(licenses, indent=4)
"""
Function that updates json file
"""
with open('licenses.json','r') as licDict:
licenses=json.loads(licDict.read())
if project in licenses.keys():
print('project in licenses.json')
else:
print('we do not have the license, adding into licenses.json')
licenses[project]=dict(info)
licJson=json.dumps(licenses, indent=4)

with open('licenses.json','w') as licFile:
licFile.write(licJson)
with open('licenses.json','w') as licFile:
licFile.write(licJson)

def main():
project=args.project
info=licenseInfo(project)
updateJson(project,info)
project=args.project
info=licenseInfo(project)
updateJson(project,info)

main()

0 comments on commit 4d674a2

Please sign in to comment.