Skip to content

Commit

Permalink
feat: Add antomatically identifying url
Browse files Browse the repository at this point in the history
antomatically identifying url
redirect arxiv abs url to its pdf url
  • Loading branch information
weipengOO98 committed Aug 11, 2021
1 parent 94d98d3 commit a019c65
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ref_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ def handle_author(author: str):
return author


def handle_url(url: str):
try:
arxiv_identifier = re.compile('http://arxiv.org/abs/([\d\.]+)').findall(url)[0]
url = f'http://arxiv.org/pdf/{arxiv_identifier}.pdf'
except:
pass
return url


def bib_parser(bibref: str):
parser = BibTexParser(common_strings=True)
parser.ignore_nonstandard_types = False
Expand All @@ -51,7 +60,12 @@ def bib_parser(bibref: str):
year = entry['year']
except:
year = '**UNKNOWN_YEAR**'
lines.append(f"1. **{title}**, *{author}*, {journal}, {year}. [[paper]()][[code]()]")
try:
url = entry['url']
url = handle_url(url)
except:
url = ''
lines.append(f"1. **{title}**, *{author}*, {journal}, {year}. [[paper]({url})][[code]()]")
target = '\n'.join(lines)
return target

Expand Down

0 comments on commit a019c65

Please sign in to comment.