Datasets:

Modalities:
Text
Formats:
json
Languages:
English
Libraries:
Datasets
pandas
License:
michaelmior commited on
Commit
784c46c
·
verified ·
1 Parent(s): e761a34

Add script for fetching licenses

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. get_licenses.py +60 -0
  3. licenses.json +3 -0
.gitattributes CHANGED
@@ -1,2 +1,3 @@
1
  *.jsonl.gz filter=lfs diff=lfs merge=lfs -text
2
  commits.json filter=lfs diff=lfs merge=lfs -text
 
 
1
  *.jsonl.gz filter=lfs diff=lfs merge=lfs -text
2
  commits.json filter=lfs diff=lfs merge=lfs -text
3
+ licenses.json filter=lfs diff=lfs merge=lfs -text
get_licenses.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import json
3
+ import os
4
+ import sys
5
+
6
+ import requests
7
+ import requests_ratelimiter
8
+ import tqdm
9
+
10
+
11
+ def get_license(session, repo):
12
+ headers = {
13
+ "Accept": "application/vnd.github+json",
14
+ "Authorization": "Bearer " + os.environ["GITHUB_TOKEN"],
15
+ "X-GitHub-Api-Version": "2022-11-28",
16
+ }
17
+
18
+ try:
19
+ r = session.get(
20
+ "https://api.github.com/repos/" + repo + "/license",
21
+ headers=headers,
22
+ timeout=10,
23
+ )
24
+ except (
25
+ requests.exceptions.ConnectionError,
26
+ requests.exceptions.ReadTimeout,
27
+ ):
28
+ # Skip on request error
29
+ return None
30
+ else:
31
+ # Get the commit hashes
32
+ obj = r.json()
33
+ if obj.get("license"):
34
+ return obj["license"]["spdx_id"]
35
+ return None
36
+
37
+
38
+ def main():
39
+ # Initialize a new session
40
+ session = requests.Session()
41
+ adapter = requests_ratelimiter.LimiterAdapter(per_second=2)
42
+ session.mount("http://", adapter)
43
+ session.mount("https://", adapter)
44
+
45
+ with open("repos.csv", "r") as csvfile:
46
+ # Count number of rows and reset
47
+ reader = csv.DictReader(csvfile)
48
+ repos = set(row["repository"] for row in reader)
49
+
50
+ for repo in tqdm.tqdm(repos):
51
+ # Remove github.com/ from the beginning and fetch the license
52
+ repo = repo.split("/", maxsplit=1)[1]
53
+ license = get_license(session, repo)
54
+ obj = {"repository": repo, "license": license}
55
+ json.dump(obj, sys.stdout)
56
+ sys.stdout.write("\n")
57
+
58
+
59
+ if __name__ == "__main__":
60
+ main()
licenses.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f04854dd486decac89335f6e547ea20820e3f2020c1452fcfdda080172751d7c
3
+ size 93380