-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalmanax.go
More file actions
60 lines (49 loc) · 1.12 KB
/
almanax.go
File metadata and controls
60 lines (49 loc) · 1.12 KB
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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
"time"
)
// sanitizeJSON is a workaround due to a bad format of the "API" used in the project
// TODO: parse website and generate a proper API
func sanitizeJSON(s []byte) []byte {
json := string(s)
json = strings.TrimPrefix(json, "<pre>")
json = strings.TrimSuffix(json, "</pre>")
return []byte(json)
}
func getAlmanaxCalendar() AlmanaxCalendar {
almanaxCalJSON := "https://almanax.ordre2vlad.fr/source.php?lang=fr"
resp, err := http.Get(almanaxCalJSON)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
body = sanitizeJSON(body)
var cal AlmanaxCalendar
err = json.Unmarshal(body, &cal)
if err != nil {
log.Fatal(err)
}
return cal
}
func getDailyAlmanax() AlmanaxEvent {
cal := getAlmanaxCalendar()
dofusServerLoc, err := time.LoadLocation("Europe/Paris")
if err != nil {
log.Fatal(err)
}
now := time.Now().In(dofusServerLoc)
_, month, day := now.Date()
today := fmt.Sprintf("%02d/%02d", day, month)
event := cal[today]
return event
}