Created
April 14, 2016 10:52
-
-
Save scholich/c0e028829308cd1f759878ba8aa71a54 to your computer and use it in GitHub Desktop.
Convert a zotero exported bibtex file to wiki format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Convert a zotero exported bibtex file to wiki format for the journal scan. | |
Take the first bibfile in the current directory and print the wikiformat. | |
""" | |
import glob | |
# open file | |
bibfiles = glob.glob('*.bib') | |
for name in bibfiles: | |
name = bibfiles[0] | |
articles = [] | |
with open(name) as f: | |
article = "" | |
for line in f: | |
if "article{" in line: | |
article = "" | |
article += line | |
if line.strip() == "}": | |
# add article to articles and reset | |
articles.append(article) | |
wikilines = [] | |
for a in articles: | |
author = None | |
url = None | |
title = None | |
for l in a.split('\n'): | |
if 'author' in l: | |
author = l.strip().replace('{', '').replace('}', '').replace('author = ', '')[:-1] | |
if 'title =' in l and 'journal' not in l: | |
title = l.strip().replace('{', '').replace('}', '').replace('title = ', '')[:-1] | |
if 'url =' in l: | |
url = l.strip().strip('},').strip('url = {') | |
wikilines.append('#%s<br>[%s %s]' % (author, url, title)) | |
print name | |
s = '\n'.join(wikilines) | |
print s | |
with open(name[:-4] + '.txt', 'w') as f: | |
f.write(s) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment