-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodifier.coffee
More file actions
executable file
·46 lines (35 loc) · 1.22 KB
/
modifier.coffee
File metadata and controls
executable file
·46 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/local/bin/coffee
fs = require('fs')
parse = require('csv-parse')
stringify = require('csv-stringify')
optimist = require('optimist')
coffeescript = require('coffee-script')
argv = null
window = {}
onCsvStringified = (err, output) ->
if err != null
console.log(err.stack)
return
fs.writeFileSync(argv.output, output, "utf8")
onCsvParsed = (err, array) ->
if err != null
console.log(err.stack)
return
arrayModified = window.dataPreprocessor(array)
options = {delimiter: ';'}
stringify(arrayModified, options, (args...) -> onCsvStringified(args...))
main = () ->
argv = optimist
.usage('Usage: $0 -input [csv] -output [csv] -modifier [coffee]')
.demand(['input','output','modifier'])
.describe('input', 'Your csv data file in accepted format')
.describe('output', 'The name of result csv file')
.describe('modifier', 'The file with coffeescript modification code')
.argv
modifierText = fs.readFileSync(argv.modifier, "utf8")
compiledSource = coffeescript.compile(modifierText)
eval(compiledSource)
buf = fs.readFileSync(argv.input, "utf8")
options = {delimiter: ';', auto_parse: true}
parse(buf, options, (args...) -> onCsvParsed(args...) )
main()