-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
50 lines (44 loc) · 1.07 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
// (defn host-to-json [host] (slurp (str host "/system/export.json")))
package main
import (
"io/ioutil"
"os"
"github.com/fuck-capitalism/agora-bridge/fedwiki/parsing"
)
// (doseq [page pages]
// (let [filename (str path "/" (page :slug) ".md")]
// (spit filename (page :content))
// (let [file (java.io.File. filename)]
// (-> file (.setLastModified (long (page :created))))
// (println (str "wrote " filename)))))))
func CreateRecord(rec parsing.Record, path string) error {
filename := path + "/" + rec.Slug + ".md"
err := ioutil.WriteFile(filename, []byte(rec.Content), 0644)
if err != nil {
return err
}
err = os.Chtimes(filename, rec.Created, rec.Created)
if err != nil {
return err
}
return nil
}
func main() {
url := os.Args[1] + "/system/export.json"
path := os.Args[2]
err := os.MkdirAll(path, os.ModePerm)
if err != nil {
panic(err)
}
json, err := parsing.GetJson(url)
if err != nil {
panic(err)
}
records := parsing.JsonToRecords(json)
for _, rec := range records {
err := CreateRecord(rec, path)
if err != nil {
panic(err)
}
}
}