-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilter_by_user.py
57 lines (40 loc) · 1.58 KB
/
filter_by_user.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
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
import bibtexparser
usernames = {'wagter', 'croon', 'smeur', 'remes', 'hamaza', 'popovic'}
print(' --- Read all papers ---')
parser = bibtexparser.bparser.BibTexParser(common_strings=True)
parser.ignore_nonstandard_types = False
with open('./website/all.bib', encoding="utf8") as bibtex_file:
bibtex_str = bibtex_file.read()
bib_database = bibtexparser.loads(bibtex_str, parser=parser)
user_paper_database = {}
for u in usernames:
user_paper_database[u] = bibtexparser.bibdatabase.BibDatabase()
print(' === Filter ===')
for b in bib_database.entries:
#print(b)
if not ('author' in b):
print('ERROR!', b)
print('------------------------------------------------------------------------')
continue
authors = b['author']
for u in usernames:
user_paper = False
if u in authors.lower():
user_paper = True
if user_paper:
if ('url' in b) and (not ('pdf' in b)):
b['pdf'] = b['url']
#if 'abstract' in b:
# b.pop('abstract')
user_paper_database[u].entries.append(b)
# dump
for u in usernames:
print(' - output bib for', u)
writer = bibtexparser.bwriter.BibTexWriter()
writer.indent = '\t' # indent entries with 4 spaces instead of one
writer.order_entries_by = 'year'
writer.align_values = True
with open('userbibs/user_'+u+'.bib', 'w', encoding='utf8') as bibfile:
bibfile.write('# AUTOGENERATED\n# \n\n')
bibfile.write(writer.write(user_paper_database[u]).replace('&',r'\&'))
print('Done')