-
Notifications
You must be signed in to change notification settings - Fork 0
/
zotbib-rofi-helper
executable file
·45 lines (32 loc) · 1.2 KB
/
zotbib-rofi-helper
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
#!/usr/bin/env python3
import re
import sys
BIB_FILE = "/media/storage/documents/zotero/library.bib"
pdf_dat_file = "/home/rajeshkumar/data/bib_data"
AUTH_COL = "#bdae93"
with open(BIB_FILE) as file:
content = file.read().strip()
bibfileorig = re.sub(r"(\\[^a-zA-Z\d\s])*[{}]*", "", content).strip()
bibfile = bibfileorig.split("\n\n")
n_papers = len(bibfile)
title = re.findall(r"(?<= title = )(.*)(?=,\n)", bibfileorig)
year = re.findall(r"(?<= year = )(\d{4})(?=.*,\n)", bibfileorig)
author = re.findall(r"(?<= author = )(.*)(?=,\n)", bibfileorig)
pdf = re.findall(r"(?<= file = )(.*\.pdf)|(.*\.djvu)", bibfileorig)
outstr = ""
if not len(title)==len(year)==len(author)==len(pdf)==n_papers:
print('title\t',len(title))
print('year\t',len(year))
print('author\t',len(author))
print('pdf\t',len(pdf))
print('papers\t',n_papers)
raise Exception("Information not of equal dimensions.")
for _ in range(n_papers):
outstr += "<b>"+title[_]+"</b>" + "\n"
outstr += (
f"<span color='{AUTH_COL}'><i> " + author[_] + f"</i> ({year[_]})</span>|"
)
pdfs = "\n".join([_[0] for _ in pdf])
with open(pdf_dat_file, "w") as file:
file.write(pdfs)
print(outstr.strip()[:-1])