This repository was archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
64 lines (56 loc) · 2.1 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import requests, json, time
from collections import defaultdict
from models import Library
def fetch_library(org):
api_key = os.getenv("LIBRARIESIO_API_KEY")
base_url = "https://libraries.io/api/github/"+ org +"/projects?api_key=" + api_key
response = requests.get(base_url)
if response.status_code == 404 or response.status_code == 500:
return {}
response.raise_for_status()
data = response.json()
mapping = [
("deprecation_reason", "deprecation_reason"),
("description", "description"),
("name", "name"),
("forks", "forks"),
("homepage", "homepage"),
("keywords", "keywords"),
("language", "language"),
("stars", "stars"),
("latest_download_url", "latest_download_url"),
("latest_stable_release_number", "latest_stable_release_number"),
("latest_stable_release_published_at", "latest_stable_release_published_at"),
("license_normalized", "license_normalized"),
("licenses", "licenses"),
("normalized_licenses", "normalized_licenses"),
("library_manager_url", "library_manager_url"),
("platform", "platform"),
("rank", "rank"),
("repository_url", "repository_url"),
("status", "status"),
]
org_libraries = defaultdict(list)
if len(data) > 0:
for pack in data:
current_dict = {}
for key, json_key in mapping:
try:
current_dict[key] = str(pack[json_key])
except KeyError:
current_dict[key] = None
p = Library(**current_dict)
for k, v in p.to_dict().items():
org_libraries[k].append(v)
return org_libraries
def fetch_libraries(orgs):
json_orgs = json.loads(json.dumps(orgs))
all_libs = defaultdict(list)
for k,v in enumerate(json_orgs["login"]):
if json_orgs["platform"][k] == "GitHub":
time.sleep(1)
libraries = fetch_library(v)
for key in libraries:
all_libs[key].extend(libraries[key])
return all_libs