-
Notifications
You must be signed in to change notification settings - Fork 1
/
nightwave.go
127 lines (116 loc) · 3.87 KB
/
nightwave.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package parser
import (
"regexp"
"strconv"
"sync"
"time"
"github.com/bitti09/go-wfapi/datasources"
"github.com/bitti09/go-wfapi/helper"
"github.com/buger/jsonparser"
)
// DailyChallenges - DailyChallenges
type DailyChallenges struct {
ID string
Ends int64
Started int64
Active bool
Reputation int64
Description string
Title string
}
// WeeklyChallenges - WeeklyChallenges
type WeeklyChallenges struct {
ID string
Ends int64
Started int64
Active bool
Reputation int64
Description string
Title string
}
// WeeklyEliteChallenges - WeeklyEliteChallenges
type WeeklyEliteChallenges struct {
ID string
Ends int64
Started int64
Active bool
Reputation int64
Description string
Title string
}
// Nightwave - Nightwave
type Nightwave struct {
ID string
Ends string
Started string
Season int64
Tag string
Phase int64
params string
possibleChallenges string
DailyChallenges []DailyChallenges
WeeklyChallenges []WeeklyChallenges
WeeklyEliteChallenges []WeeklyEliteChallenges
}
// Nightwavedata export Alertsdata
var Nightwavedata = make(map[int]map[string][]Nightwave)
// ParseNightwave Parse Nightwave Season Info
func ParseNightwave(platformno int, platform string, lang string, wg *sync.WaitGroup) {
defer wg.Done()
if _, ok := Nightwavedata[platformno]; !ok {
Nightwavedata[platformno] = make(map[string][]Nightwave)
}
data := datasources.Apidata[platformno]
var nightwave []Nightwave
var dchallenge []DailyChallenges
var wchallenge []WeeklyChallenges
var welitechallenge []WeeklyEliteChallenges
errfissures, _ := jsonparser.GetString(data, "SeasonInfo")
if errfissures != "" {
return
}
timenow := time.Now().Unix()
// fmt.Println("nightwave reached")
id := "1"
ended, _ := jsonparser.GetString(data, "SeasonInfo", "Expiry", "$date", "$numberLong")
activation, _ := jsonparser.GetString(data, "SeasonInfo", "Activation", "$date", "$numberLong")
season, _ := jsonparser.GetInt(data, "SeasonInfo", "Season")
tag1, _ := jsonparser.GetString(data, "SeasonInfo", "AffiliationTag")
phase, _ := jsonparser.GetInt(data, "SeasonInfo", "Phase")
jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
idc, _ := jsonparser.GetString(value, "_id", "$oid")
endedc, _ := jsonparser.GetString(value, "Expiry", "$date", "$numberLong")
endedc1, _ := strconv.ParseInt(endedc, 10, 64)
endedc2 := endedc1 / 1000
// fmt.Println(idc)
// fmt.Println(endedc2)
activationc, _ := jsonparser.GetString(value, "Activation", "$date", "$numberLong")
activationc1, _ := strconv.ParseInt(activationc, 10, 64)
activationc2 := activationc1 / 1000
mission, _ := jsonparser.GetString(value, "Challenge")
cdesc := helper.Langtranslate2(mission, lang)
reputation, _ := jsonparser.GetInt(value, "reputation")
active := true // temp
if endedc2 > timenow {
active = true // temp
}
daily, _ := jsonparser.GetBoolean(value, "Daily")
elite, _ := regexp.MatchString(`WeeklyHard.*`, mission)
if daily {
dailyc := DailyChallenges{idc, endedc2, activationc2, active, reputation, cdesc[1], cdesc[0]}
dchallenge = append(dchallenge, dailyc)
}
if !daily && !elite {
weekc := WeeklyChallenges{idc, endedc2, activationc2, active, reputation, cdesc[1], cdesc[0]}
wchallenge = append(wchallenge, weekc)
}
if !daily && elite {
weekelitec := WeeklyEliteChallenges{idc, endedc2, activationc2, active, reputation, cdesc[1], cdesc[0]}
welitechallenge = append(welitechallenge, weekelitec)
}
}, "SeasonInfo", "ActiveChallenges")
w := Nightwave{id, ended, activation, season + 1, tag1,
phase, "", "", dchallenge, wchallenge, welitechallenge}
nightwave = append(nightwave, w)
Nightwavedata[platformno][lang] = nightwave
}