-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
49 lines (41 loc) · 856 Bytes
/
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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/anonyindian/telegraph-api-spec/telegraph"
"github.com/anaskhan96/soup"
)
const API_URL = "https://telegra.ph/api"
func main() {
resp, err := soup.Get(API_URL)
if err != nil {
os.Exit(1)
}
doc := soup.HTMLParse(resp)
telegraph.FindMethodsAndTypes(doc)
result := telegraph.MakeResult(doc)
WriteFile("telegraph.json", MakeJSON(result))
}
/*
UTILITIES
*/
func MakeJSON(result telegraph.Result) []byte {
b, err := json.MarshalIndent(&result, "", " ")
if err != nil {
panic(err.Error())
}
return b
}
func WriteFile(filename string, data []byte) (*os.File, error) {
_, err := os.Open(filename)
if err == nil {
os.Remove(filename)
}
err = ioutil.WriteFile(filename, data, 0644)
if err != nil {
return nil, err
}
f, err := os.Open(filename)
return f, err
}