-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintreferences.py
executable file
·74 lines (52 loc) · 1.94 KB
/
printreferences.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import bibtexparser as bibp
import os.path
import pandas as pd
authors = pd.read_csv('authors_2018_1', header=0, low_memory=False)
surnames = list(authors['Surname'])
nationalities = list(authors['Nationality'])
# print nationalities
with open('files/ozstar18.bib') as bibfile:
bib_database = bibp.bparser.BibTexParser(common_strings=True).parse_file(bibfile)
if os.path.exists('printreferences_test.out'):
os.remove('printreferences_test.out')
outputfile = open('printreferences_test.out', 'w')
print("no of references:", len(bib_database.entries))
for entry in bib_database.entries:
entry_authors = entry['author']
entry_authors = entry_authors.replace('\n', ' ')
outputfile.write('\\item ',)
for author in entry_authors.split('and '):
author = author.replace('{', '')
author = author.replace('}', '')
author = author.replace('\'', '')
author = author.replace('\"', '')
author = author.replace('\\', '')
author = author.replace('^', '')
nationality = 'meh'
if author.split(',')[0] in surnames:
index = surnames.index(author.split(',')[0])
nationality = nationalities[index]
if nationality == 'A':
# print '{\\bf ' + author[:-1] + '}; ',
outputfile.write('{\\bf ' + author[:-1] + '}; ',)
else:
# print author[:-1] + '; ',
outputfile.write(author[:-1] + '; ',)
# print '\\emph{' + entry['title'] + '},',
# print entry['journal'] + ',',
# print 'Volume ' + entry['volume'] + ',',
# print 'Pages ' + entry['pages'] + ',',
# print entry['year'],
# print '\n',
outputfile.write('\\emph{' + entry['title'] + '}')
# outputfile.write(entry['journal'] + ', ')
if 'journal' in entry.keys():
outputfile.write(', Journal ' + entry['journal'])
if 'volume' in entry.keys():
outputfile.write(', Volume ' + entry['volume'])
if 'pages' in entry.keys():
outputfile.write(', Pages ' + entry['pages'])
if 'year' in entry.keys():
outputfile.write(', Year ' + entry['year'])
outputfile.write('\n')
outputfile.close()