/
GSE5Mlib.go
2328 lines (1916 loc) · 58.7 KB
/
GSE5Mlib.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
Copyright © 2022 chouette.21.00@gmail.com
Released under the MIT license
https://opensource.org/licenses/mit-license.php
*/
package GSE5Mlib
import (
"fmt"
"log"
"strconv"
"strings"
"time"
"os"
// "io/ioutil"
"gopkg.in/yaml.v2"
"encoding/json"
"runtime"
"net/http"
"database/sql"
_ "github.com/go-sql-driver/mysql"
"github.com/PuerkitoBio/goquery"
"github.com/dustin/go-humanize"
"SRGSE5M/SRDBlib"
ghexsrapi "github.com/Chouette2100/exsrapi"
ghsrapi "github.com/Chouette2100/srapi"
)
/*
ShowroomCGIlib
0100L1 安定版(~2021.12.26)
0100M0 vscodeでの指摘箇所の修正
0101A0 LinuxとMySQL8.0に対応する。
0101B0 OSとWebサーバに応じた処理を行うようにする。アクセスログを作成する。
0101B1 実行時パラメータをファイルから与えるように変更する。
0101C0 GetRoomInfoByAPI()に配信開始時刻の取得を追加する。
0101D0 詳細なランク情報の導入(Nrank)
0101D1 "Next Live"の表示を追加する。
0101D2 GetScoreEvery5Minutes RU20E4 に適合するバージョン
0101D3 ランクをshow_rank_subdividedからleague_labe + lshow_rank_subdivided にする。
0101E0 配信枠別貢献ポイントを導入する。
----------------------------------------------
GSE5Mlib
0101F0 Showroom.CGIlibをベースにSGE5Mlibを作成する。
0101G2 設定ファイルをyaml形式に変更する。
timetableにデータ取得時刻を保存するときstime、etimeも書き込むようにする。
0101G3 イベント終了時刻に1分を加える(終了時刻が22時00分のとき21時59分と表示されているため) <== 事実誤認による修正
0101G4 貢献ポイントランキングを取得するためイベント終了時刻の10分後までデータ取得を行う。
0101G5 NewDocument()をNewDocumentFromReader()に変更する。DBConfigにTimeLimitを追加する。
0102A0a ブロックランキングの最終結果の取得にsrapi.GetEventBlockRanking()を使用する(テスト、Event_id=30030限定)
0102B0 ルーム情報の取得でエラーが発生したときの処理を追加する。
0102C0 SRDBlibを導入したことへ対応する。
0102D0 できるだけ早く確定情報を取得する。
0102E0 Room_url_keyでプリフィックスの削除を"/"から"/r/"に変更する。
0102E1 aprev_score(prank)の抜けを補う。
0102E2 InsertIntoOrUpdateUser():stmt: = DB.Prepare()でのエラーに対してエラー処理の中でstmt.Close()を行う。
0102F0 InsertIntoOrUpdateUsers():stmtを関数内ローカル変数としてClose()のタイミングを明確にする。
0102F3 InsertIntoOrUpdateUsers():userhitoryのInsertで引数の数を合わせる。
0102F4 InsertIntoOrUpdateUser() stmtを使うところをそれぞれ別の変数にする。
*/
const Version = "0102F4"
type Event_Inf struct {
Event_ID string
Event_name string
Event_no int
MaxPoint int
Start_time time.Time
Sstart_time string
Start_date float64
End_time time.Time
Send_time string
Period string
Dperiod float64
Intervalmin int
Modmin int
Modsec int
Fromorder int
Toorder int
Resethh int
Resetmm int
Nobasis int
Maxdsp int
NoEntry int
NoRoom int // ルーム数
EventStatus string // "Over", "BeingHeld", "NotHeldYet"
Pntbasis int
Ordbasis int
League_ids string
Cmap int
Target int
Maxpoint int
// Status string // "Confirmed": イベント終了日翌日に確定した獲得ポイントが反映されている。
}
type LongName struct {
Name string
}
type Point struct {
Pnt int
Spnt string
Tpnt string
}
type PointRecord struct {
Day string
Tday time.Time
Pointlist []Point
}
type PointPerDay struct {
Eventid string
Eventname string
Period string
Usernolist []int
Longnamelist []LongName
Pointrecordlist []PointRecord
}
type RoomLevel struct {
User_name string
Genre string
Rank string
Nrank string
Prank string
Level int
Followers int
ts time.Time
Sts string
}
type RoomLevelInf struct {
Userno int
User_name string
RoomLevelList []RoomLevel
}
/*
type PerSlot struct {
Timestart time.Time
Dstart string
Tstart string
Tend string
Point string
Ipoint int
Tpoint string
}
type PerSlotInf struct {
Eventname string
Eventid string
Period string
Roomname string
Roomid int
Perslotlist []PerSlot
}
*/
type ColorInf struct {
Color string
Colorvalue string
Selected string
}
type ColorInfList []ColorInf
type RoomInfo struct {
Name string // ルーム名のリスト
Longname string
Shortname string
Account string // アカウントのリスト、アカウントは配信のURLの最後の部分の英数字です。
ID string // IDのリスト、IDはプロフィールのURLの最後の部分で5~6桁の数字です。
Userno int
// APIで取得できるデータ(1)
Genre string
Rank string
Nrank string
Prank string
Followers int
Sfollowers string
Level int
Slevel string
// APIで取得できるデータ(2)
Point int // イベント終了直後はイベントページから取得できることもある
Spoint string
Istarget string
Graph string
Iscntrbpoint string
Color string
Colorvalue string
Colorinflist ColorInfList
Formid string
Eventid string
Status string
Statuscolor string
}
type RoomInfoList []RoomInfo
/*
// sort.Sort()のための関数三つ
func (r RoomInfoList) Len() int {
return len(r)
}
func (r RoomInfoList) Swap(i, j int) {
r[i], r[j] = r[j], r[i]
}
func (r RoomInfoList) Choose(from, to int) (s RoomInfoList) {
s = r[from:to]
return
}
var SortByFollowers bool
// 降順に並べる
func (r RoomInfoList) Less(i, j int) bool {
// return e[i].point < e[j].point
if SortByFollowers {
return r[i].Followers > r[j].Followers
} else {
return r[i].Point > r[j].Point
}
}
*/
/*
var Dbhost string
var Dbname string
var Dbuser string
var Dbpw string
*/
var Event_inf Event_Inf
// var Db *sql.DB
// var Err error
var OS string
var WebServer string
type Color struct {
Name string
Value string
}
// https://www.fukushihoken.metro.tokyo.lg.jp/kiban/machizukuri/kanren/color.files/colorudguideline.pdf
var Colorlist2 []Color = []Color{
{"red", "#FF2800"},
{"yellow", "#FAF500"},
{"green", "#35A16B"},
{"blue", "#0041FF"},
{"skyblue", "#66CCFF"},
{"lightpink", "#FFD1D1"},
{"orange", "#FF9900"},
{"purple", "#9A0079"},
{"brown", "#663300"},
{"lightgreen", "#87D7B0"},
{"white", "#FFFFFF"},
{"gray", "#77878F"},
}
var Colorlist1 []Color = []Color{
{"cyan", "cyan"},
{"magenta", "magenta"},
{"yellow", "yellow"},
{"royalblue", "royalblue"},
{"coral", "coral"},
{"khaki", "khaki"},
{"deepskyblue", "deepskyblue"},
{"crimson", "crimson"},
{"orange", "orange"},
{"lightsteelblue", "lightsteelblue"},
{"pink", "pink"},
{"sienna", "sienna"},
{"springgreen", "springgreen"},
{"blueviolet", "blueviolet"},
{"salmon", "salmon"},
{"lime", "lime"},
{"red", "red"},
{"darkorange", "darkorange"},
{"skyblue", "skyblue"},
{"lightpink", "lightpink"},
}
type Event struct {
EventID string
EventName string
Selected string
}
type User struct {
Userno int
Userlongname string
Selected string
}
type CurrentScore struct {
Rank int
Srank string
Userno int
Shorturl string
Eventid string
Username string
Roomrank string
Roomnrank string
Roomlevel string
Followers string
NextLive string
Point int
Spoint string
Sdfr string
Pstatus string
Ptime string
Qstatus string
Qtime string
}
type DBConfig struct {
WebServer string `yaml:"WebServer"`
HTTPport string `yaml:"HTTPport"`
SSLcrt string `yaml:"SSLcrt"`
SSLkey string `yaml:"SSLkey"`
Dbhost string `yaml:"Dbhost"`
Dbname string `yaml:"Dbname"`
Dbuser string `yaml:"Dbuser"`
Dbpw string `yaml:"Dbpw"`
TimeLimit int `yaml:"TimeLimit"`
}
var Dbconfig *DBConfig
// 設定ファイルを読み込む
// 以下の記事を参考にさせていただきました。
// 【Go初学】設定ファイル、環境変数から設定情報を取得する
// https://note.com/artefactnote/n/n8c22d1ac4b86
//
func LoadConfig(filePath string) (dbconfig *DBConfig, err error) {
content, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
content = []byte(os.ExpandEnv(string(content)))
result := &DBConfig{}
result.TimeLimit = 99999
if err := yaml.Unmarshal(content, result); err != nil {
return nil, err
}
return result, nil
}
func GetSerialFromYymmddHhmmss(yymmdd, hhmmss string) (tserial float64) {
var year, month, day, hh, mm, ss int
t19000101 := time.Date(1899, 12, 30, 0, 0, 0, 0, time.Local)
fmt.Sscanf(yymmdd, "%d/%d/%d", &year, &month, &day)
fmt.Sscanf(hhmmss, "%d:%d:%d", &hh, &mm, &ss)
t1 := time.Date(year, time.Month(month), day, hh, mm, ss, 0, time.Local)
tserial = t1.Sub(t19000101).Minutes() / 60.0 / 24.0
return
}
func GetUserInfForHistory() (status int) {
status = 0
// select distinct(nobasis) from event
stmt, err := SRDBlib.Db.Prepare("select distinct(nobasis) from event")
if err != nil {
// log.Fatal(err)
log.Printf("err=[%s]\n", err.Error())
status = -1
return
}
defer stmt.Close()
rows, err := stmt.Query()
if err != nil {
// log.Fatal(err)
log.Printf("err=[%s]\n", err.Error())
status = -1
return
}
defer rows.Close()
var roominf RoomInfo
var roominflist RoomInfoList
for rows.Next() {
err := rows.Scan(&roominf.Userno)
if err != nil {
// log.Fatal(err)
log.Printf("err=[%s]\n", err.Error())
status = -1
return
}
if roominf.Userno != 0 {
roominf.ID = fmt.Sprintf("%d", roominf.Userno)
roominflist = append(roominflist, roominf)
}
}
if err = rows.Err(); err != nil {
// log.Fatal(err)
log.Printf("err=[%s]\n", err.Error())
status = -1
return
}
eventid := ""
// Update user , Insert into userhistory
for _, roominf := range roominflist {
sql := "select currentevent from user where userno = ?"
err := SRDBlib.Db.QueryRow(sql, roominf.Userno).Scan(&eventid)
if err != nil {
log.Printf("err=[%s]\n", err.Error())
status = -1
}
roominf.Genre, roominf.Rank, roominf.Nrank, roominf.Prank, roominf.Level, roominf.Followers, roominf.Name, roominf.Account, _, status =
GetRoomInfoByAPI(roominf.ID)
if status == 0 && roominf.Followers != 0 {
InsertIntoOrUpdateUser(time.Now().Truncate(time.Second), eventid, roominf)
} else {
log.Printf("GetUserInfForHistory(): GetRoomInfoByAPI() returned status=%d, roominf=%+v\n", status, roominf)
}
}
return
}
func GetEventListByAPI(eventinflist *[]Event_Inf) (status int) {
status = 0
last_page := 1
total_count := 1
for page := 1; page <= last_page; page++ {
URL := "https://www.showroom-live.com/api/event/search?page=" + fmt.Sprintf("%d", page)
log.Printf("GetEventListByAPI() URL=%s\n", URL)
resp, err := http.Get(URL)
if err != nil {
// 一時的にデータが取得できない。
log.Printf("GetEventListByAPI() err=%s\n", err.Error())
// panic(err)
status = -1
return
}
defer resp.Body.Close()
// JSONをデコードする。
// 次の記事を参考にさせていただいております。
// Go言語でJSONに泣かないためのコーディングパターン
// https://qiita.com/msh5/items/dc524e38073ed8e3831b
var result interface{}
decoder := json.NewDecoder(resp.Body)
if err := decoder.Decode(&result); err != nil {
log.Printf("GetEventListByAPI() err=%s\n", err.Error())
// panic(err)
status = -2
return
}
if page == 1 {
value, _ := result.(map[string]interface{})["last_page"].(float64)
last_page = int(value)
value, _ = result.(map[string]interface{})["total_count"].(float64)
total_count = int(value)
log.Printf("GetEventListByAPI() total_count=%d, last_page=%d\n", total_count, last_page)
}
noroom := 30
if page == last_page {
noroom = total_count % 30
if noroom == 0 {
noroom = 30
}
}
for i := 0; i < noroom; i++ {
var eventinf Event_Inf
tres := result.(map[string]interface{})["event_list"].([]interface{})[i]
ttres := tres.(map[string]interface{})["league_ids"]
norec := len(ttres.([]interface{}))
if norec == 0 {
continue
}
log.Printf("norec =%d\n", norec)
eventinf.League_ids = ""
/*
for j := 0; j < norec; j++ {
eventinf.League_ids += ttres.([]interface{})[j].(string) + ","
}
*/
eventinf.League_ids = ttres.([]interface{})[norec-1].(string)
if eventinf.League_ids != "60" {
continue
}
eventinf.Event_ID, _ = tres.(map[string]interface{})["event_url_key"].(string)
eventinf.Event_name, _ = tres.(map[string]interface{})["event_name"].(string)
// log.Printf("id=%s, name=%s\n", eventinf.Event_ID, eventinf.Event_name)
started_at, _ := tres.(map[string]interface{})["started_at"].(float64)
eventinf.Start_time = time.Unix(int64(started_at), 0)
eventinf.Sstart_time = eventinf.Start_time.Format("06/01/02 15:04")
ended_at, _ := tres.(map[string]interface{})["ended_at"].(float64)
eventinf.End_time = time.Unix(int64(ended_at), 0)
eventinf.Send_time = eventinf.End_time.Format("06/01/02 15:04")
(*eventinflist) = append((*eventinflist), eventinf)
}
// resp.Body.Close()
}
return
}
// idで指定した配信者さんの獲得ポイントを取得する。
// 戻り値は 獲得ポイント、順位、上位とのポイント差(1位の場合は2位とのポイント差)、イベント名
// レベルイベントのときは順位、上位とのポイント差は0がセットされる。
func GetPointsByAPI(id string) (Point, Rank, Gap int, EventID string) {
// 獲得ポイントなどの配信者情報を得るURL(このURLについては記事参照)
URL := "https://www.showroom-live.com/api/room/event_and_support?room_id=" + id
resp, err := http.Get(URL)
if err != nil {
// 一時的にデータが取得できない。
// panic(err)
return 0, 0, 0, "**Error** http.Get(URL)"
}
defer resp.Body.Close()
// JSONをデコードする。
// 次の記事を参考にさせていただいております。
// Go言語でJSONに泣かないためのコーディングパターン
// https://qiita.com/msh5/items/dc524e38073ed8e3831b
var result interface{}
decoder := json.NewDecoder(resp.Body)
if err := decoder.Decode(&result); err != nil {
// panic(err)
return 0, 0, 0, "**Error** http.Get(URL)"
}
// イベントが終わっている、イベント参加をとりやめた、SHOWROOMをやめた、などの対応
if result.(map[string]interface{})["event"] == nil {
return 0, 0, 0, "not held yet./over./not entry."
}
if result.(map[string]interface{})["event"].(map[string]interface{})["ranking"] != nil {
// ランキングのあるイベントの場合
// (順位に応じて特典が与えられるイベント、ただし獲得ポイントに対して特典が与えられる場合でも順位付けがある場合はこちら)
// 獲得ポイント
l, _ := result.(map[string]interface{})["event"].(map[string]interface{})["ranking"].(map[string]interface{})["point"].(float64)
// 順位
m, _ := result.(map[string]interface{})["event"].(map[string]interface{})["ranking"].(map[string]interface{})["rank"].(float64)
// ポイント差
n, _ := result.(map[string]interface{})["event"].(map[string]interface{})["ranking"].(map[string]interface{})["gap"].(float64)
Point = int(l)
Rank = int(m)
Gap = int(n)
// イベント名
EventID, _ = result.(map[string]interface{})["event"].(map[string]interface{})["event_url"].(string)
EventID = strings.Replace(EventID, "https://www.showroom-live.com/event/", "", -1)
} else if result.(map[string]interface{})["event"].(map[string]interface{})["quest"] != nil {
// レベルイベント(ランキングのないイベント)の場合
// (アバ権やステッカーなど獲得ポイントに応じて特典が与えられるイベント、ただし順位付けがある場合は除く)
// 獲得ポイント
l, _ := result.(map[string]interface{})["event"].(map[string]interface{})["quest"].(map[string]interface{})["support"].(map[string]interface{})["current_point"].(float64)
// 順位
m := 0.0
// ポイント差
n := 0.0
Point = int(l)
Rank = int(m)
Gap = int(n)
// イベント名
EventID, _ = result.(map[string]interface{})["event"].(map[string]interface{})["event_url"].(string)
EventID = strings.Replace(EventID, "https://www.showroom-live.com/event/", "", -1)
} else {
// 上記ランキングイベントでもレベルイベントでもない場合
// もしこのようなケースが存在するならJSONを確認して新たにコーディングする
log.Println(" N/A")
return 0, 0, 0, "N/A"
}
return
}
/*
*/
func GetIsOnliveByAPI(room_id string) (
isonlive bool, // true: 配信中
startedat time.Time, // 配信開始時刻(isonliveがtrueのときだけ意味があります)
status int,
) {
status = 0
// https://qiita.com/takeru7584/items/f4ba4c31551204279ed2
url := "https://www.showroom-live.com/api/room/profile?room_id=" + room_id
resp, err := http.Get(url)
if err != nil {
// 一時的にデータが取得できない。
// resp.Body.Close()
// panic(err)
status = -1
return
}
defer resp.Body.Close()
// JSONをデコードする。
// 次の記事を参考にさせていただいております。
// Go言語でJSONに泣かないためのコーディングパターン
// https://qiita.com/msh5/items/dc524e38073ed8e3831b
var result interface{}
decoder := json.NewDecoder(resp.Body)
if err := decoder.Decode(&result); err != nil {
// panic(err)
status = -2
return
}
// 配信中か?
isonlive, _ = result.(map[string]interface{})["is_onlive"].(bool)
if isonlive {
// 配信開始時刻の取得
value, _ := result.(map[string]interface{})["current_live_started_at"].(float64)
startedat = time.Unix(int64(value), 0).Truncate(time.Second)
// log.Printf("current_live_stared_at %f %v\n", value, startedat)
}
return
}
func GetRoomInfoByAPI(room_id string) (
genre string,
rank string,
nrank string,
prank string,
level int,
followers int,
roomname string,
roomurlkey string,
startedat time.Time,
status int,
) {
status = 0
// https://qiita.com/takeru7584/items/f4ba4c31551204279ed2
url := "https://www.showroom-live.com/api/room/profile?room_id=" + room_id
resp, err := http.Get(url)
if err != nil {
// 一時的にデータが取得できない。
// resp.Body.Close()
// panic(err)
status = -1
return
}
defer resp.Body.Close()
// JSONをデコードする。
// 次の記事を参考にさせていただいております。
// Go言語でJSONに泣かないためのコーディングパターン
// https://qiita.com/msh5/items/dc524e38073ed8e3831b
var result interface{}
decoder := json.NewDecoder(resp.Body)
if err := decoder.Decode(&result); err != nil {
// panic(err)
status = -2
return
}
value, _ := result.(map[string]interface{})["follower_num"].(float64)
followers = int(value)
genre, _ = result.(map[string]interface{})["genre_name"].(string)
value, _ = result.(map[string]interface{})["next_score"].(float64)
rank, _ = result.(map[string]interface{})["league_label"].(string)
ranks, _ := result.(map[string]interface{})["show_rank_subdivided"].(string)
rank = rank + " | " + ranks
nrank = humanize.Comma(int64(value))
value, _ = result.(map[string]interface{})["prev_score"].(float64)
prank = humanize.Comma(int64(value))
value, _ = result.(map[string]interface{})["room_level"].(float64)
level = int(value)
roomname, _ = result.(map[string]interface{})["room_name"].(string)
roomurlkey, _ = result.(map[string]interface{})["room_url_key"].(string)
// 配信開始時刻の取得
value, _ = result.(map[string]interface{})["current_live_started_at"].(float64)
startedat = time.Unix(int64(value), 0).Truncate(time.Second)
// log.Printf("current_live_stared_at %f %v\n", value, startedat)
return
}
func GetNextliveByAPI(room_id string) (
nextlive string,
status int,
) {
status = 0
// https://qiita.com/takeru7584/items/f4ba4c31551204279ed2
url := "https://www.showroom-live.com/api/room/next_live?room_id=" + room_id
resp, err := http.Get(url)
if err != nil {
// 一時的にデータが取得できない。
// resp.Body.Close()
// panic(err)
status = -1
return
}
defer resp.Body.Close()
// JSONをデコードする。
// 次の記事を参考にさせていただいております。
// Go言語でJSONに泣かないためのコーディングパターン
// https://qiita.com/msh5/items/dc524e38073ed8e3831b
var result interface{}
decoder := json.NewDecoder(resp.Body)
if err := decoder.Decode(&result); err != nil {
// panic(err)
status = -2
return
}
nextlive, _ = result.(map[string]interface{})["text"].(string)
return
}
func UpdateRoomInf(eventid, suserno, longname, shortname, istarget, graph, color, iscntrbpoint string) (status int) {
status = 0
userno, _ := strconv.Atoi(suserno)
sql := "update user set longname=?, shortname=? where userno = ?"
stmt1, err := SRDBlib.Db.Prepare(sql)
if err != nil {
log.Printf("UpdateRoomInf() error(Update/Prepare) err=%s\n", err.Error())
status = -1
return
}
defer stmt1.Close()
_, err = stmt1.Exec(longname, shortname, userno)
if err != nil {
log.Printf("UpdateRoomInf() error(InsertIntoOrUpdateUser() Update/Exec) err=%s\n", err.Error())
status = -2
return
}
// eventno, _, _ := SelectEventNoAndName(eventid)
if istarget == "1" {
istarget = "Y"
} else {
istarget = "N"
}
if graph == "1" {
graph = "Y"
} else {
graph = "N"
}
if iscntrbpoint == "1" {
iscntrbpoint = "Y"
} else {
iscntrbpoint = "N"
}
// sql = "update eventuser set istarget=?, graph=?, color=? where eventno=? and userno=?"
sql = "update eventuser set istarget=?, graph=?, color=?, iscntrbpoints=? where eventid=? and userno=?"
stmt2, err := SRDBlib.Db.Prepare(sql)
if err != nil {
log.Printf("UpdateRoomInf() error(Update/Prepare) err=%s\n", err.Error())
status = -1
return
}
defer stmt2.Close()
_, err = stmt2.Exec(istarget, graph, color, iscntrbpoint, eventid, userno)
if err != nil {
log.Printf("error(InsertIntoOrUpdateUser() Update/Exec) err=%s\n", err.Error())
status = -2
}
return
}
func UpdateEventuserSetPoint(eventid, userid string, point int) (status int) {
status = 0
// eventno, _, _ := SelectEventNoAndName(eventid)
userno, _ := strconv.Atoi(userid)
sql := "update eventuser set point=? where eventid = ? and userno = ?"
stmt, err := SRDBlib.Db.Prepare(sql)
if err != nil {
log.Printf("UpdateEventuserSetPoint() error (Update/Prepare) err=%s\n", err.Error())
status = -1
return
}
defer stmt.Close()
_, err = stmt.Exec(point, eventid, userno)
if err != nil {
log.Printf("error(UpdateEventuserSetPoint() Update/Exec) err=%s\n", err.Error())
status = -2
}
return
}
func InsertEventInf(eventinf *Event_Inf) (
status int,
) {
if _, _, status = SelectEventNoAndName((*eventinf).Event_ID); status != 0 {
sql := "INSERT INTO event(eventid, event_name, period, starttime, endtime, noentry,"
sql += " intervalmin, modmin, modsec, "
sql += " Fromorder, Toorder, Resethh, Resetmm, Nobasis, Maxdsp, Cmap, target, maxpoint "
sql += ") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
log.Printf("db.Prepare(sql)\n")
stmt, err := SRDBlib.Db.Prepare(sql)
if err != nil {
log.Printf("error InsertEventInf() (INSERT/Prepare) err=%s\n", err.Error())
status = -1
return
}
defer stmt.Close()
log.Printf("row.Exec()\n")
_, err = stmt.Exec(
(*eventinf).Event_ID,
(*eventinf).Event_name,
(*eventinf).Period,
(*eventinf).Start_time,
(*eventinf).End_time,
(*eventinf).NoEntry,
(*eventinf).Intervalmin,
(*eventinf).Modmin,
(*eventinf).Modsec,
(*eventinf).Fromorder,
(*eventinf).Toorder,
(*eventinf).Resethh,
(*eventinf).Resetmm,
(*eventinf).Nobasis,
(*eventinf).Maxdsp,
(*eventinf).Cmap,
(*eventinf).Target,
(*eventinf).Maxpoint,
)
if err != nil {
log.Printf("error InsertEventInf() (INSERT/Exec) err=%s\n", err.Error())
status = -2
}
} else {
status = 1
}
return
}
func UpdateEventInf(eventinf *Event_Inf) (
status int,
) {
if _, _, status = SelectEventNoAndName((*eventinf).Event_ID); status == 0 {
sql := "Update event set "
sql += " event_name=?,"
sql += " period=?,"
sql += " starttime=?,"
sql += " endtime=?,"
sql += " noentry=?,"
sql += " intervalmin=?,"
sql += " modmin=?,"
sql += " modsec=?,"
sql += " Fromorder=?,"
sql += " Toorder=?,"
sql += " Resethh=?,"
sql += " Resetmm=?,"
sql += " Nobasis=?,"
sql += " Target=?,"
sql += " Maxdsp=?, "
sql += " cmap=?, "
sql += " maxpoint=? "
// sql += " where eventno = ?"
sql += " where eventid = ?"
log.Printf("db.Prepare(sql)\n")
stmt, err := SRDBlib.Db.Prepare(sql)
if err != nil {
log.Printf("UpdateEventInf() error (Update/Prepare) err=%s\n", err.Error())
status = -1
return
}
defer stmt.Close()
log.Printf("stmt.Exec()\n")
_, err = stmt.Exec(
(*eventinf).Event_name,
(*eventinf).Period,
(*eventinf).Start_time,
(*eventinf).End_time,
(*eventinf).NoEntry,
(*eventinf).Intervalmin,
(*eventinf).Modmin,
(*eventinf).Modsec,
(*eventinf).Fromorder,
(*eventinf).Toorder,
(*eventinf).Resethh,
(*eventinf).Resetmm,
(*eventinf).Nobasis,
(*eventinf).Target,
(*eventinf).Maxdsp,
(*eventinf).Cmap,
(*eventinf).Maxpoint,
(*eventinf).Event_ID,
)
if err != nil {
log.Printf("error UpdateEventInf() (update/Exec) err=%s\n", err.Error())
status = -2
}
} else {
status = 1
}