-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathop.js
150 lines (131 loc) · 3.84 KB
/
op.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var fs = require('fs');
var program = require('commander');
var db = require('./db.js');
var dirs = require('./dirs');
//convert excel file(s) in directory to csv
program
.command("convert-files")
.description("convert excel files to csv")
.option("-y, --year <year>", "year")
.option("-q, --quarter <quarter>", "quarter")
.option("-b, --body <body>", "body")
.option("-f, --fund <fund number>", "fund")
.option("-s, --srcdir <name>","path of Excel files, default:"+dirs.excel)
.option("-t, --trgdir <name>","path of CSV files, default:"+dirs.csv)
.option("-o, --overwrite","overwrite existing CSV files, default: false")
.action(function(args){
if (!process.argv.slice(3).length) {
this.outputHelp();
return;
}
var srcdir = args.srcdir || dirs.excel;
var trgdir = args.trgdir || dirs.csv;
var overwrite = args.overwrite || false;
try{
require("./files_loader").convertFilesCmd(args.body, args.fund, args.year, args.quarter, srcdir, trgdir, overwrite);
}
catch(err){
console.error("Error:" + err);
}
})
//create table in database
program
.command("db-create-table")
.description("create table in database")
.option("-t, --table <name>","table name")
.action(function(args){
if (!process.argv.slice(3).length) {
this.outputHelp();
return;
}
try{
require('./db').createTable(args.table);
}
catch(err){
console.error("Error:" + err);
}
});
//truncate table in database
program
.command("db-empty-table")
.description("truncate table in database")
.option("-t, --table <name>","table name")
.action(function(args){
if (!process.argv.slice(3).length) {
this.outputHelp();
return;
}
try{
require('./db').emptyTable(args.table);
}
catch(err){
console.error("Error:" + err);
}
});
//load files to database
program
.command("db-load-files")
.description("load csv files to database")
.option("-y, --year <year>", "year")
.option("-q, --quarter <quarter>", "quarter")
.option("-b, --body <body>", "body")
.option("-f, --fund <fund number>", "fund number")
.option("-t, --table <name>","table name")
.option("-s, --srcdir <name>","path of CSV files, default:"+dirs.csv)
.option("-c, --concurrency <number>","number of concurrent DB connections, defaults to 4")
.action(function(args){
if (!process.argv.slice(3).length || !args.table) {
this.outputHelp();
return;
}
var srcdir = args.srcdir || dirs.csv;
try{
require('./dbLoader').importFilesCmd(srcdir, args.body, args.year, args.quarter, args.fund,
args.table, args.concurrency);
}
catch(err){
console.error("Error:" + err);
}
});
// program
// .command("dump-funds")
// .description("create csv files from database data")
// .action(function(){
// require('./fetcher').dumpFunds();
// });
//download and convert files in Google Doc
program
.command("fetch-google")
.description("download files in Google Doc.")
.option("-y, --year <year>", "year")
.option("-q, --quarter <quarter>", "quarter")
.option("-b, --body <body>", "body")
.option("-f, --fund <fund number>", "fund number")
.option("-t, --trgdir <name>","path of Excel files, default:"+dirs.excel)
.option("-o, --overwrite","overwrite existing Excel files, default: false")
.action(function(args){
if (!process.argv.slice(3).length) {
this.outputHelp();
return;
}
var trgdir = args.trgdir || dirs.excel;
var overwrite = args.overwrite || false;
try{
require('./fetcher').fetchKnown(args.body, args.year, args.quarter, args.fund, trgdir, overwrite);
}
catch(err){
console.error("Error:" + err);
}
});
//download and convert contributed files
// program
// .command("fetch-contrib")
// .description("download and convert contributed files")
// .action(function(){
// require('./fetcher').fetchContrib();
// });
if (!process.argv.slice(2).length) {
program.outputHelp();
return;
}
program.parse(process.argv);