-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_bib.py
151 lines (124 loc) · 4.83 KB
/
generate_bib.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import sqlite3
import re
import datetime
from bibtexparser.bwriter import BibTexWriter
from bibtexparser.bibdatabase import BibDatabase
db = sqlite3.connect('profile.db')
c = db.cursor()
db = BibDatabase()
db.entries = []
id_dict = {}
c.execute('SELECT title, authors, journal, journal_abbr, volume, pages, month, year FROM journal_paper WHERE locale = "international" ORDER BY year, month')
for row in c:
title, authors, journal, journal_abbr, volume, pages, month, year = row
title_kwd = None
authors_kwd = None
journal_kwd = None
bib_obj = {'ENTRYTYPE': 'article'}
if title is not None:
bib_obj['title'] = title
for word in re.split('[^A-Za-z0-9]', title):
word = word.lower()
if word != 'a' and word != 'the' and word != 'an':
title_kwd = word
break
if authors is not None:
bib_obj['author'] = ' AND '.join(authors.split('|'))
author_kwd = authors.split('|')[0].split(' ')[-1].lower()
if journal is not None:
bib_obj['journal'] = journal
if journal_abbr is not None and journal_abbr != '':
journal_kwd = journal_abbr
if volume is not None and volume != '':
bib_obj['volume'] = str(volume)
if pages is not None and pages != '':
bib_obj['pages'] = pages.replace('-', '--')
if year is not None:
bib_obj['year'] = str(year)
if month is not None:
m = re.match('^([0-9]+)-([0-9]+)$', month)
if m:
dateobj = datetime.date(2000, int(m.group(1)), 1)
mon1 = dateobj.strftime('%b')
dateobj = datetime.date(2000, int(m.group(2)), 1)
mon2 = dateobj.strftime('%b')
bib_obj['month'] = ', %s-%s' % (mon1, mon2)
month = int(m.group(1))
else:
m = re.match('^[0-9]+$', month)
if m:
dateobj = datetime.date(2000, int(month), 1)
mon = dateobj.strftime('%b')
bib_obj['month'] = mon
month = int(month)
if journal_kwd is not None:
bib_id = '%s%s%s%s' % (author_kwd, journal_kwd, year, title_kwd)
else:
bib_id = '%s%s%s' % (author_kwd, year, title_kwd)
if bib_id in id_dict:
raise
id_dict[bib_id] = True
bib_obj['ID'] = bib_id
print bib_id
db.entries.append(bib_obj)
c.execute('SELECT title, authors, conference, conference_abbr, volume, pages, month, year, city FROM conference_paper WHERE locale = "international" ORDER BY year, month')
for row in c:
title, authors, conference, conference_abbr, volume, pages, month, year, city = row
bib_obj = {'ENTRYTYPE': 'inproceedings'}
title_kwd = None
authors_kwd = None
conf_kwd = None
if title is not None:
bib_obj['title'] = title
for word in re.split('[^A-Za-z0-9]', title):
word = word.lower()
if word != 'a' and word != 'the' and word != 'an':
title_kwd = word
break
if authors is not None:
bib_obj['author'] = ' AND '.join(authors.split('|'))
author_kwd = authors.split('|')[0].split(' ')[-1].lower()
if conference is not None:
bib_obj['booktitle'] = 'Proceedings of %s' % (conference,)
if conference_abbr is not None:
m = re.match('^(.+) \'?[0-9]+$', conference_abbr)
if m:
conference_abbr = m.group(1)
bib_obj['booktitle'] += ' (%s)' % (conference_abbr,)
conf_kwd = re.split('[^A-Za-z0-9]', conference_abbr)[-1]
if volume is not None and volume != '':
bib_obj['volume'] = str(volume)
if pages is not None and pages != '':
bib_obj['pages'] = pages.replace('-', '--')
if year is not None:
bib_obj['year'] = str(year)
if month is not None:
month = str(month)
m = re.match('^([0-9]+)-([0-9]+)$', month)
if m:
dateobj = datetime.date(2000, int(m.group(1)), 1)
mon1 = dateobj.strftime('%b')
dateobj = datetime.date(2000, int(m.group(2)), 1)
mon2 = dateobj.strftime('%b')
bib_obj['month'] = ', %s-%s' % (mon1, mon2)
month = int(m.group(1))
else:
m = re.match('^[0-9]+$', month)
if m:
dateobj = datetime.date(2000, int(month), 1)
mon = dateobj.strftime('%b')
bib_obj['month'] = mon
month = int(month)
if conf_kwd is not None:
bib_id = '%s%s%s%s' % (author_kwd, conf_kwd, year, title_kwd)
else:
bib_id = '%s%s%s' % (author_kwd, year, title_kwd)
if bib_id in id_dict:
raise
id_dict[bib_id] = True
bib_obj['ID'] = bib_id
print bib_id
db.entries.append(bib_obj)
writer = BibTexWriter()
with open('seokhwankim.bib', 'w') as bibfile:
bibfile.write(writer.write(db))