-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (44 loc) · 1.31 KB
/
main.go
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
package main
import (
"os"
"strconv"
"strings"
"AtCoderABCReport/internal"
)
func main() {
// コマンドライン引数を取得
if len(os.Args) == 1 {
internal.OutputStderr("require config file.", true)
os.Exit(1)
}
configFileName := os.Args[1]
// 設定ファイルのチェック
if _, err := os.Stat(configFileName); err != nil {
internal.OutputStderr(err.Error(), true)
os.Exit(2)
}
// 出力ファイル名は設定ファイル名の拡張子をcsvにしたものにする
outputFileName := strings.Replace(configFileName, "yml", "csv", 1)
internal.OutputStderr("Output file: "+outputFileName, true)
// 設定ファイル読み込み
config := internal.Config{}
if err := config.ReadConfigFile(configFileName); err != nil {
internal.OutputStderr(err.Error(), true)
os.Exit(4)
}
internal.OutputStderr("Contest Number:"+strconv.Itoa(config.ContestCount), true)
internal.OutputStderr("Condition.Language:"+config.Condition.ContestLanguage, true)
// 出力ファイルの作成
outputFile, err := os.Create(outputFileName)
if err != nil {
internal.OutputStderr(err.Error(), true)
os.Exit(5)
}
defer outputFile.Close()
// スクレイピング実行
if err := internal.RunScraping(&config, outputFile); err != nil {
internal.OutputStderr(err.Error(), true)
os.Exit(6)
}
os.Exit(0)
}