Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 56 lines (46 sloc) 1.5 KB
#!/usr/bin/env python
import csv
import sys
import json
import chardet
import cStringIO
class CSVParser(object):
def __init__(self, fileobj):
data =
self.encoding = chardet.detect(data).get('encoding', 'ascii')
# Some files have Byte-order marks inserted at the start
if data[:3] == '\xef\xbb\xbf':
data = data[3:]
self.fileobj = cStringIO.StringIO(data)
def parse(self):
#dialect = csv.Sniffer().sniff(
d = csv.DictReader(self.fileobj)
data = []
# do any required conversions
for row in d:
if "author" in row:
row["author"] = row["author"].split(",")
if "editor" in row:
row["editor"] = row["editor"].split(",")
return data, {}
def parse():
parser = CSVParser(sys.stdin)
records, metadata = parser.parse()
if len(records) > 0:
sys.stdout.write(json.dumps({'records':records, 'metadata':metadata}))
sys.stderr.write('Zero records were parsed from the data')
def main():
conf = {"display_name": "CSV",
"format": "csv",
"contact": "",
"bibserver_plugin": True,
"BibJSON_version": "0.81"}
for x in sys.argv[1:]:
if x == '-bibserver':
if __name__ == '__main__':
Jump to Line
Something went wrong with that request. Please try again.