My friend helped me to write a small Python parser of my bibliography in BetterBibtex bib file and save every reference as md file in Obsidian vault.
How to use it:
1: install BetterBibtex as described in Zettlr docs. Citation key later will serve as a filename so use appropriate keys, i.e. no semicolons or other special symbols are allowed.
2. Copy the script (below) and bib file into references
folder inside your vault.
3. Run the script:
import json
import collections
def flatten(d, parent_key='', sep='_'):
items = []
for k, v in d.items():
new_key = parent_key + sep + k if parent_key else k
if isinstance(v, collections.MutableMapping):
items.extend(flatten(v, new_key, sep=sep).items())
else:
items.append((new_key, v))
return dict(items)
def flatten_publication_info(publication_info):
if publication_info.get('author', False):
publication_info['authors'] = [author['family']+' '+author['given'] for author in publication_info['author']]
publication_info = flatten(publication_info)
return publication_info
elif publication_info.get('authors', False):
publication_info['authors'] = [author['family']+' '+author['given'] for author in publication_info['authors']]
publication_info = flatten(publication_info)
return publication_info
return None
f = open('My Library.json','r', encoding='utf8')
data = json.load(f)
for elem in data:
try:
flat_publication = flatten_publication_info(elem)
if flat_publication:
filename = 'ZOT' + elem['id'] + '.md'
writer = open(filename,'w+', encoding='utf8')
title = flat_publication['title']
abstract = flat_publication.get('abstract','Empty')
authors = ';'.join(flat_publication['authors'])
writer.write('tags: #zotero #reference\nlinks: [[Zotero library]] [[Readings MOC]]\n') #header
writer.write('### %s\n ###### Authors\n%s\n ###### Abstract\n%s' % (title,authors,abstract))
writer.close()
except Exception as e:
print('Problems with %s' % (elem['id']))
print(e)
It will produce a lot of md files that you could reference from Obsidian. It will look like this: