Skip to content

Commit 1d11e4e

Browse files
committed
Fixes #47 Implements CSV to JSON servlet integrations
1 parent 0e12c4c commit 1d11e4e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

loklak.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import requests
1010
from xmljson import badgerfish as bf
1111
from json import dumps
12+
import csv
1213

1314

1415
class Loklak(object):
@@ -63,9 +64,13 @@ def xmlToJson(self, xmlData = None):
6364
jsonData = dumps(bf.data(fromstring(xmlData)))
6465
return jsonData
6566

66-
def csvToJson(self):
67+
def csvToJson(self, csvData = None, fieldnamesList = None):
6768
"""Converts CSV to JSON as the service"""
68-
69+
jsonData = ''
70+
if csvData:
71+
data = csv.DictReader( csvData, fieldnames = fieldnamesList)
72+
jsonData = json.dumps( [ row for row in data ] )
73+
return out
6974

7075
def hello(self):
7176
"""Gives a hello"""

0 commit comments

Comments
 (0)