-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patharxiv-generate-bibtex-entry
executable file
·83 lines (66 loc) · 2.43 KB
/
arxiv-generate-bibtex-entry
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# @article{RSZ16,
# author = {Orit E. Raz and Micha Sharir and Frank de Zeeuw},
# journal = {arXiv e-prints},
# note = {\href{https://arxiv.org/abs/1607.03600}{arXiv:1607.03600 [cs.CO]}},
# title = {The {E}lekes-{S}zab{\'{o}} Theorem in four dimensions},
# year = {2016}
# }
import os
import sys
import json
from bibtexparser.bwriter import BibTexWriter
from bibtexparser.bibdatabase import BibDatabase
from arxiv import escape_filename
from arxiv import sanitize
from arxiv import get_lastname_first_letter
log = lambda *x, **y: print(*x, **y, file=sys.stderr)
def main ( uid ) :
path_format_metadata = '~/library/arxiv/metadata/{}.json'
uid_escaped = escape_filename(uid)
path_metadata = os.path.expanduser(path_format_metadata.format(uid_escaped))
with open(path_metadata) as fp:
metadata = json.load(fp)
title = sanitize(metadata['title'])
authors = list(map(lambda x: sanitize(x['name']), metadata['authors']))
# links = metadata['links']
published = metadata['published']
# updated = metadata['updated']
# summary = sanitize(metadata['summary'])
category = metadata["arxiv_primary_category"]["term"]
year = published[:4]
month = published[5:7]
day = published[8:10]
abbr = ''.join(
sorted(map(get_lastname_first_letter, authors))) + year[2:4]
log('url: {}'.format(metadata['id']))
log('arxiv-id: {}'.format(uid))
log('Published: {}'.format(published))
log('Title: {}'.format(title))
log('Authors: {}'.format(', '.join(authors)))
format_link = '{{\href{{https://arxiv.org/abs/{uid}}}{{arXiv:{uid} [{category}]}}}}'
entry = {
'ENTRYTYPE': 'misc',
# 'ENTRYTYPE': 'article',
'archivePrefix': 'arXiv',
# 'journal': 'arXiv e-prints',
'ID': abbr,
'author': ' and '.join(authors),
'title': title,
'year': str(int(year)),
'month': str(int(month)),
# 'note': format_link.format(uid=uid, category=category),
'eprint': uid,
'primaryClass': category,
}
db = BibDatabase()
db.entries = [ entry ]
writer = BibTexWriter()
writer.indent = ' '
writer.entry_separator = ''
writer.comma_first = True
writer.display_order = ('title', 'author', 'year', 'month', 'journal', 'note', 'archivePrefix', 'eprint', 'primaryClass')
sys.stdout.write(writer.write(db))
if __name__ == '__main__':
uid = sys.argv[1]
main(uid)