Datasets:

License:
snidiff1 commited on
Commit
713557d
1 Parent(s): bfca101

Submit MP3 Here Due to Large Output Size

Browse files
Files changed (2) hide show
  1. snidiff1.json.gz +3 -0
  2. snidiff1.py +65 -0
snidiff1.json.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac740323fdb5bbad206be0764c06c99f1cda3f7ece6aabe2070fb12afcccddd7
3
+ size 97501745
snidiff1.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json, re
2
+ import requests
3
+ from urlextract import URLExtract
4
+ import sys, gzip
5
+
6
+
7
+ utid = 'snidiff1'
8
+ base= { 'model':'https://huggingface.co/', 'data': 'https://huggingface.co/datasets/', 'source': 'https://' }
9
+ post = '/raw/main/README.md'
10
+ postGH = '/blob/master/README.md'
11
+ postGHalt = '/blob/main/README.md' # or it could be 'blob/main/README.md'
12
+
13
+ extU = URLExtract()
14
+ DOIpattern = r'\b(10\.\d{4,9}\/[-._;()/:A-Z0-9]+)\b/i'
15
+ #r1\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'<>])[[:graph:]])+)\b'
16
+
17
+ def extractURLs (c):
18
+ res = extU.find_urls (c)
19
+ return res
20
+
21
+ def extractDOIs (c):
22
+ res = re.findall (DOIpattern, c)
23
+ return res
24
+
25
+ fo = gzip.open(f"output/{utid}.json.gz", 'w')
26
+
27
+ def run (tp):
28
+ post0 = post
29
+ #put errors=ignore, was getting decoding errors
30
+ with open(f"input/{utid}_{tp}", 'r', errors='ignore') as f:
31
+ for line in f:
32
+ line = line.strip ()
33
+ if tp == 'source':
34
+ (npapers,line) = line.split(';')
35
+ post0 = postGH
36
+ print(line)
37
+
38
+ url = base[tp] + f"{line}{post0}"
39
+ print(url)
40
+ r = requests.get (url)
41
+ #github returns repos that do not exist, need to detect that here
42
+ #2xx status codes are sucesses, others are not
43
+ if r.status_code < 200 or r.status_code > 299:
44
+ print("error, trying main")
45
+
46
+ #github when you give master instead of main, that might cause issues as well
47
+ url = base[tp] + f"{line}{postGHalt}"
48
+ print(url)
49
+ r = requests.get (url)
50
+ if r.status_code < 200 or r.status_code > 299:
51
+ print("error code returned")
52
+ continue
53
+
54
+ content = r.text
55
+ urls = extractURLs(content)
56
+ dois = extractDOIs(content)
57
+ res = { 'ID': line, 'type': tp, 'url': url, 'content': content, 'links': urls, 'dois': dois }
58
+ out = json.dumps(res, ensure_ascii=False)
59
+ fo.write((out+"\n").encode())
60
+
61
+ run('model')
62
+ run('data')
63
+ run('source')
64
+
65
+ fo.close()