-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
65 lines (57 loc) · 1.84 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
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"fmt"
"github.com/golang/protobuf/proto"
"golang.org/x/text/encoding/charmap"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
const listNamePlaceHolder = "<list-name>.txt"
var (
listName = flag.String("list-name", "ZAPRETINFO", "Name of the list")
input = flag.String("input", filepath.Join("./", "z-i", "dump.csv"), "Path to the Zapret-Info CSV")
geoSiteFile = flag.String("geosite-filename", "geosite.dat", "Name of the output file")
plainTextFile = flag.String("plaintext-filename", listNamePlaceHolder, "Name of the plaintext output file")
outputPath = flag.String("output-dir", "./publish", "Output path to the generated files")
)
func main() {
flag.Parse()
domainList, parseErr := Unmarshal(charmap.Windows1251.NewDecoder(), strings.ToUpper(*listName), *input)
if parseErr != nil {
panic(parseErr)
}
if err := domainList.Flatten(); err != nil {
fmt.Println("Failed:", err)
os.Exit(1)
}
if geoSites := domainList.ToGeoSites(); geoSites != nil {
geoSiteData, err := proto.Marshal(geoSites)
if err != nil {
fmt.Println("Failed:", err)
os.Exit(1)
}
if err := os.MkdirAll(*outputPath, 0755); err != nil {
fmt.Println("Failed:", err)
os.Exit(1)
}
if err := ioutil.WriteFile(filepath.Join(*outputPath, *geoSiteFile), geoSiteData, 0644); err != nil {
fmt.Println("Failed:", err)
os.Exit(1)
}
fmt.Printf("%s has been generated successfully in '%s'.\n", *geoSiteFile, *outputPath)
}
var outputName string
if *plainTextFile == listNamePlaceHolder {
outputName = *listName + ".txt"
} else {
outputName = *plainTextFile
}
if err := ioutil.WriteFile(filepath.Join(*outputPath, outputName), domainList.ToPlainText(), 0644); err != nil {
fmt.Println("Failed:", err)
os.Exit(1)
}
fmt.Printf("%s has been generated successfully in '%s'.\n", outputName, *outputPath)
}