Skip to content

Instantly share code, notes, and snippets.

@shayanb
Last active December 8, 2015 02:11
Show Gist options
  • Save shayanb/70217da4701a124a027f to your computer and use it in GitHub Desktop.
Save shayanb/70217da4701a124a027f to your computer and use it in GitHub Desktop.
Bibtex_to_SAFBuilder
#python script to convert bibtex for SAFBuilder CSV
#Make Papers bibtex export available to be used with SAFBuilder to make a Simple Archive Format to be able to import in dSpace (I know! lol)
import bibtexparser
import csv
import urllib2
with open('cryptolibrary.bib') as bibtex_file:
bibtex_str = bibtex_file.read()
#print bibtex_str
#filename => parse local-url anything after last /
#dc.title =>title
#dc.date.issued => year
#dc.description.abstract => abstract
#dc.contributor.author => author
#dc.date.available => year
#dc.identifier.uri => link
bib_database = bibtexparser.loads(bibtex_str)
headers = [["filename","dc.title","dc.contributor.author","dc.date.issued","dc.identifier.uri","dc.description.abstract"]]
with open('test.csv', "w") as csvout:
entity = csv.writer(csvout, delimiter=",")
entity.writerows(headers)
for paper in bib_database.entries:
print paper
try:
author = paper['author'].encode('utf-8')
except:
author = "UNKNOWN"
try:
title = paper['title'].encode('utf-8')
except:
title = "UNKNOWN"
try:
year = paper['year'].encode('utf-8')
except:
year = "UNKNOWN"
try:
filename = paper['local-url'].split("/")[-1].encode('utf-8')
except:
filename = "UNKNOWN"
try:
abstract = paper['abstract'].encode('utf-8')
except:
abstract = ""
try:
author = paper['author'].encode('utf-8')
except:
author = "UNKNOWN"
try:
uri = paper['link'].encode('utf-8')
except:
uri = "UNKNOWN"
one_item = [[urllib2.unquote(filename),title,author,year,uri,abstract]]
print one_item
entity.writerows(one_item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment