+182
@@ -0,0 +1,182 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"honoka-chan/database"
|
||||
"honoka-chan/model"
|
||||
"honoka-chan/utils"
|
||||
)
|
||||
|
||||
func AnalysisApi1Data(path string) {
|
||||
apiData := utils.ReadAllText(path)
|
||||
if apiData != "" {
|
||||
var obj model.Response
|
||||
err := json.Unmarshal([]byte(apiData), &obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var data interface{}
|
||||
err = json.Unmarshal(obj.ResponseData, &data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// resultType := reflect.TypeOf(data)
|
||||
// if resultType.Kind() == reflect.Map {
|
||||
// data = data.(map[string]interface{})
|
||||
// }
|
||||
result := data.([]interface{})
|
||||
for k, v := range result {
|
||||
m, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
key := ""
|
||||
switch k {
|
||||
case 0:
|
||||
key = "live_status_result"
|
||||
case 1:
|
||||
key = "live_list_result"
|
||||
case 2:
|
||||
key = "unit_list_result"
|
||||
case 3:
|
||||
key = "unit_deck_result"
|
||||
case 4:
|
||||
key = "unit_support_result"
|
||||
case 5:
|
||||
key = "owning_equip_result"
|
||||
case 6:
|
||||
key = "costume_list_result"
|
||||
case 7:
|
||||
key = "album_unit_result"
|
||||
case 8:
|
||||
key = "scenario_status_result"
|
||||
case 9:
|
||||
key = "subscenario_status_result"
|
||||
case 10:
|
||||
key = "event_scenario_result"
|
||||
case 11:
|
||||
key = "multi_unit_scenario_result"
|
||||
case 12:
|
||||
key = "product_result"
|
||||
case 13:
|
||||
key = "banner_result"
|
||||
case 14:
|
||||
key = "item_marquee_result"
|
||||
case 15:
|
||||
key = "user_intro_result"
|
||||
case 16:
|
||||
key = "special_cutin_result"
|
||||
case 17:
|
||||
key = "award_result"
|
||||
case 18:
|
||||
key = "background_result"
|
||||
case 19:
|
||||
key = "stamp_result"
|
||||
case 20:
|
||||
key = "exchange_point_result"
|
||||
case 21:
|
||||
key = "live_se_result"
|
||||
case 22:
|
||||
key = "live_icon_result"
|
||||
case 23:
|
||||
key = "item_list_result"
|
||||
case 24:
|
||||
key = "marathon_result"
|
||||
case 25:
|
||||
key = "challenge_result"
|
||||
}
|
||||
|
||||
if key != "" {
|
||||
database.RedisCli.HSet(database.RedisCtx, "temp_dataset", key, string(m))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func AnalysisApi2Data(path string) {
|
||||
apiData := utils.ReadAllText(path)
|
||||
if apiData != "" {
|
||||
var obj model.Response
|
||||
err := json.Unmarshal([]byte(apiData), &obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var data interface{}
|
||||
err = json.Unmarshal(obj.ResponseData, &data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// resultType := reflect.TypeOf(data)
|
||||
// if resultType.Kind() == reflect.Map {
|
||||
// data = data.(map[string]interface{})
|
||||
// }
|
||||
result := data.([]interface{})
|
||||
for k, v := range result {
|
||||
m, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
key := ""
|
||||
switch k {
|
||||
case 0:
|
||||
key = "login_topinfo_result"
|
||||
case 1:
|
||||
key = "login_topinfo_once_result"
|
||||
case 2:
|
||||
key = "unit_accessory_result"
|
||||
case 3:
|
||||
key = "museum_result"
|
||||
}
|
||||
|
||||
if key != "" {
|
||||
database.RedisCli.HSet(database.RedisCtx, "temp_dataset", key, string(m))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func AnalysisApi3Data(path string) {
|
||||
apiData := utils.ReadAllText(path)
|
||||
if apiData != "" {
|
||||
var obj model.Response
|
||||
err := json.Unmarshal([]byte(apiData), &obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var data interface{}
|
||||
err = json.Unmarshal(obj.ResponseData, &data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// resultType := reflect.TypeOf(data)
|
||||
// if resultType.Kind() == reflect.Map {
|
||||
// data = data.(map[string]interface{})
|
||||
// }
|
||||
result := data.([]interface{})
|
||||
for k, v := range result {
|
||||
m, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
key := ""
|
||||
switch k {
|
||||
case 0:
|
||||
key = "profile_livecnt_result"
|
||||
case 1:
|
||||
key = "profile_card_ranking_result"
|
||||
case 2:
|
||||
key = "profile_info_result"
|
||||
}
|
||||
|
||||
if key != "" {
|
||||
database.RedisCli.HSet(database.RedisCtx, "temp_dataset", key, string(m))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func SyncNotesList() {
|
||||
db, err := sql.Open("sqlite3", "assets/live.db")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer func() {
|
||||
db.Close()
|
||||
fmt.Println("Sync notes list done!")
|
||||
}()
|
||||
db.SetMaxOpenConns(1)
|
||||
|
||||
sql := `SELECT live_setting_id,notes_setting_asset,notes_list FROM live_setting_m ORDER BY live_setting_id ASC`
|
||||
rows, err := db.Query(sql)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
liveList := make(map[int]string)
|
||||
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var asset string
|
||||
var notes interface{}
|
||||
err = rows.Scan(&id, &asset, ¬es)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if notes != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
liveList[id] = asset
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
// fmt.Println(liveList)
|
||||
|
||||
for id, asset := range liveList {
|
||||
url := "https://card.niconi.co.ni/live/" + asset
|
||||
fmt.Println(url)
|
||||
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
if res.StatusCode == http.StatusNotFound {
|
||||
fmt.Println(res.StatusCode)
|
||||
continue
|
||||
}
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
_ = res.Body.Close()
|
||||
// fmt.Println(string(body))
|
||||
|
||||
regex := regexp.MustCompile("var lives = (.*?)\n")
|
||||
matchs := regex.FindSubmatch(body)
|
||||
match := string(matchs[len(matchs)-1])
|
||||
|
||||
match = strings.ReplaceAll(match, "{\\\"", "{\"")
|
||||
match = strings.ReplaceAll(match, "\\\":", "\":")
|
||||
match = strings.ReplaceAll(match, ",\\\"", ",\"")
|
||||
match = strings.ReplaceAll(match, "notes_list\":\"", "notes_list\":")
|
||||
match = strings.ReplaceAll(match, "]\"}]", "]}]")
|
||||
|
||||
var notesList string
|
||||
gjson.Parse(match).ForEach(func(key, value gjson.Result) bool {
|
||||
notesList = value.Get("notes_list").String()
|
||||
return true
|
||||
})
|
||||
// fmt.Println(notesList)
|
||||
|
||||
if notesList == "" {
|
||||
fmt.Println("notes_list is null")
|
||||
continue
|
||||
}
|
||||
|
||||
stmt, err := db.Prepare("UPDATE live_setting_m SET notes_list = ? WHERE live_setting_id = ?")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
ret, err := stmt.Exec(notesList, id)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
r, err := ret.RowsAffected()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
fmt.Println("RowsAffected:", r)
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
+6
-179
@@ -1,182 +1,9 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"honoka-chan/database"
|
||||
"honoka-chan/model"
|
||||
"honoka-chan/utils"
|
||||
)
|
||||
|
||||
func AnalysisApi1Data(path string) {
|
||||
apiData := utils.ReadAllText(path)
|
||||
if apiData != "" {
|
||||
var obj model.Response
|
||||
err := json.Unmarshal([]byte(apiData), &obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var data interface{}
|
||||
err = json.Unmarshal(obj.ResponseData, &data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// resultType := reflect.TypeOf(data)
|
||||
// if resultType.Kind() == reflect.Map {
|
||||
// data = data.(map[string]interface{})
|
||||
// }
|
||||
result := data.([]interface{})
|
||||
for k, v := range result {
|
||||
m, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
key := ""
|
||||
switch k {
|
||||
case 0:
|
||||
key = "live_status_result"
|
||||
case 1:
|
||||
key = "live_list_result"
|
||||
case 2:
|
||||
key = "unit_list_result"
|
||||
case 3:
|
||||
key = "unit_deck_result"
|
||||
case 4:
|
||||
key = "unit_support_result"
|
||||
case 5:
|
||||
key = "owning_equip_result"
|
||||
case 6:
|
||||
key = "costume_list_result"
|
||||
case 7:
|
||||
key = "album_unit_result"
|
||||
case 8:
|
||||
key = "scenario_status_result"
|
||||
case 9:
|
||||
key = "subscenario_status_result"
|
||||
case 10:
|
||||
key = "event_scenario_result"
|
||||
case 11:
|
||||
key = "multi_unit_scenario_result"
|
||||
case 12:
|
||||
key = "product_result"
|
||||
case 13:
|
||||
key = "banner_result"
|
||||
case 14:
|
||||
key = "item_marquee_result"
|
||||
case 15:
|
||||
key = "user_intro_result"
|
||||
case 16:
|
||||
key = "special_cutin_result"
|
||||
case 17:
|
||||
key = "award_result"
|
||||
case 18:
|
||||
key = "background_result"
|
||||
case 19:
|
||||
key = "stamp_result"
|
||||
case 20:
|
||||
key = "exchange_point_result"
|
||||
case 21:
|
||||
key = "live_se_result"
|
||||
case 22:
|
||||
key = "live_icon_result"
|
||||
case 23:
|
||||
key = "item_list_result"
|
||||
case 24:
|
||||
key = "marathon_result"
|
||||
case 25:
|
||||
key = "challenge_result"
|
||||
}
|
||||
|
||||
if key != "" {
|
||||
database.RedisCli.HSet(database.RedisCtx, "temp_dataset", key, string(m))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func AnalysisApi2Data(path string) {
|
||||
apiData := utils.ReadAllText(path)
|
||||
if apiData != "" {
|
||||
var obj model.Response
|
||||
err := json.Unmarshal([]byte(apiData), &obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var data interface{}
|
||||
err = json.Unmarshal(obj.ResponseData, &data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// resultType := reflect.TypeOf(data)
|
||||
// if resultType.Kind() == reflect.Map {
|
||||
// data = data.(map[string]interface{})
|
||||
// }
|
||||
result := data.([]interface{})
|
||||
for k, v := range result {
|
||||
m, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
key := ""
|
||||
switch k {
|
||||
case 0:
|
||||
key = "login_topinfo_result"
|
||||
case 1:
|
||||
key = "login_topinfo_once_result"
|
||||
case 2:
|
||||
key = "unit_accessory_result"
|
||||
case 3:
|
||||
key = "museum_result"
|
||||
}
|
||||
|
||||
if key != "" {
|
||||
database.RedisCli.HSet(database.RedisCtx, "temp_dataset", key, string(m))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func AnalysisApi3Data(path string) {
|
||||
apiData := utils.ReadAllText(path)
|
||||
if apiData != "" {
|
||||
var obj model.Response
|
||||
err := json.Unmarshal([]byte(apiData), &obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var data interface{}
|
||||
err = json.Unmarshal(obj.ResponseData, &data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// resultType := reflect.TypeOf(data)
|
||||
// if resultType.Kind() == reflect.Map {
|
||||
// data = data.(map[string]interface{})
|
||||
// }
|
||||
result := data.([]interface{})
|
||||
for k, v := range result {
|
||||
m, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
key := ""
|
||||
switch k {
|
||||
case 0:
|
||||
key = "profile_livecnt_result"
|
||||
case 1:
|
||||
key = "profile_card_ranking_result"
|
||||
case 2:
|
||||
key = "profile_info_result"
|
||||
}
|
||||
|
||||
if key != "" {
|
||||
database.RedisCli.HSet(database.RedisCtx, "temp_dataset", key, string(m))
|
||||
}
|
||||
}
|
||||
}
|
||||
func init() {
|
||||
AnalysisApi1Data("assets/api1.json")
|
||||
AnalysisApi2Data("assets/api2.json")
|
||||
AnalysisApi3Data("assets/api3.json")
|
||||
// ListUnitData()
|
||||
go SyncNotesList()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user