-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdd_tools.py
30 lines (26 loc) · 962 Bytes
/
gdd_tools.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
import re
def repotest(string):
"""Check to see if a repository is referenced in the paper.
string A character string returned from geodeepdive highlights.
returns None or the string matched.
"""
test = re.search(r'((github)|(gitlab)|(bitbucket)).com\/((\s{0,1})[\w,\-,\_]+\/*){1,2}', string)
if test is None:
output = {'repo': None, 'highlight': string}
else:
test_no_space = re.sub(r'\s', '', test[0])
test_no_punct = re.sub(r'[^\w\s]$', '', test_no_space)
output = {'repo': test_no_punct, 'highlight': string}
return output
def empty_none(val):
"""Clean out None values.
val A Python object that may or may not have None values.
returns a Python object with all None values replaced by ''.
"""
for k in val.keys():
if isinstance(val[k], dict):
empty_none(val[k])
else:
if val[k] is None:
val[k] = ''
return val