Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arturgrigor committed Mar 27, 2012
0 parents commit 8fe6da4
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions csv2plist.py
@@ -0,0 +1 @@
import os, sys, plistlibimport csv, codecs, cStringIOclass UTF8Recoder: """ Iterator that reads an encoded stream and reencodes the input to UTF-8 """ def __init__(self, f, encoding): self.reader = codecs.getreader(encoding)(f) def __iter__(self): return self def next(self): return self.reader.next().encode("utf-8")class UnicodeReader: """ A CSV reader which will iterate over lines in the CSV file "f", which is encoded in the given encoding. """ def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds): f = UTF8Recoder(f, encoding) self.reader = csv.reader(f, dialect=dialect, **kwds) def next(self): row = self.reader.next() return [unicode(s, "utf-8") for s in row] def __iter__(self): return selfinfile = ''outfile = ''args = sys.argv[1:]if(len(args) == 1): infile = args[0] outfile = infile.replace(".csv", ".plist")if(len(args) == 2): infile = args[0] outfile = args[1]i = 0headers = []plist = []csvr = UnicodeReader(open(infile, 'rb'), delimiter=',')for row in csvr: if (i == 0): headers = row if (i > 0): dictionary = dict(zip(headers, row)) plist.append(dictionary) i+=1plistlib.writePlist(plist, outfile)
Expand Down

0 comments on commit 8fe6da4

Please sign in to comment.