@@ -164,44 +164,43 @@ func TibiaCharactersCharacterV3(c *gin.Context) {
164
164
165
165
// Running query on every .TableContainer
166
166
ReaderHTML .Find (".TableContainer" ).Each (func (index int , s * goquery.Selection ) {
167
-
168
167
// Storing HTML into CharacterDivHTML
169
168
CharacterDivHTML , err := s .Html ()
170
169
if err != nil {
171
170
log .Fatal (err )
172
171
}
173
172
174
- if strings .Contains (CharacterDivHTML , "Text\" >Character Information" ) {
173
+ switch {
174
+ case strings .Contains (CharacterDivHTML , "Text\" >Character Information" ):
175
175
// Character Information
176
176
CharacterSection = "characterinformation"
177
- } else if strings .Contains (CharacterDivHTML , "Text\" >Account Badges" ) {
177
+ case strings .Contains (CharacterDivHTML , "Text\" >Account Badges" ):
178
178
// Account Badges
179
179
CharacterSection = "accountbadges"
180
- } else if strings .Contains (CharacterDivHTML , "Text\" >Account Achievements" ) {
180
+ case strings .Contains (CharacterDivHTML , "Text\" >Account Achievements" ):
181
181
// Account Achievements
182
182
CharacterSection = "accountachievements"
183
- } else if strings .Contains (CharacterDivHTML , "Text\" >Character Deaths" ) {
183
+ case strings .Contains (CharacterDivHTML , "Text\" >Character Deaths" ):
184
184
// Character Deaths
185
185
CharacterSection = "characterdeaths"
186
- } else if strings .Contains (CharacterDivHTML , "Text\" >Account Information" ) {
186
+ case strings .Contains (CharacterDivHTML , "Text\" >Account Information" ):
187
187
// Account Information
188
188
CharacterSection = "accountinformation"
189
- } else if strings .Contains (CharacterDivHTML , "Text\" >Search Character" ) {
189
+ case strings .Contains (CharacterDivHTML , "Text\" >Search Character" ):
190
190
// Search Character
191
191
CharacterSection = "searchcharacter"
192
- } else if strings .Contains (CharacterDivHTML , "Text\" >Characters" ) {
192
+ case strings .Contains (CharacterDivHTML , "Text\" >Characters" ):
193
193
// Characters
194
194
CharacterSection = "characters"
195
195
}
196
196
197
197
// parsing CharacterDivHTML to goquery format
198
198
CharacterDivQuery , _ := goquery .NewDocumentFromReader (strings .NewReader (CharacterDivHTML ))
199
199
200
- if CharacterSection == "characterinformation" || CharacterSection == "accountinformation" {
201
-
200
+ switch CharacterSection {
201
+ case "characterinformation" , "accountinformation" :
202
202
// Running query over each tr in character content container
203
203
CharacterDivQuery .Find (localDivQueryString ).Each (func (index int , s * goquery.Selection ) {
204
-
205
204
// Storing HTML into CharacterTrHTML
206
205
CharacterTrHTML , err := s .Html ()
207
206
if err != nil {
@@ -218,8 +217,8 @@ func TibiaCharactersCharacterV3(c *gin.Context) {
218
217
subma1 := regex1 .FindAllStringSubmatch (CharacterTrHTML , - 1 )
219
218
220
219
if len (subma1 ) > 0 {
221
-
222
- if subma1 [ 0 ][ 1 ] == "Name" {
220
+ switch TibiaDataSanitizeNbspSpaceString ( subma1 [ 0 ][ 1 ]) {
221
+ case "Name" :
223
222
Tmp := strings .Split (subma1 [0 ][2 ], "<" )
224
223
CharacterInformationData .Name = strings .TrimSpace (Tmp [0 ])
225
224
if strings .Contains (Tmp [0 ], ", will be deleted at" ) {
@@ -231,33 +230,32 @@ func TibiaCharactersCharacterV3(c *gin.Context) {
231
230
CharacterInformationData .Traded = true
232
231
CharacterInformationData .Name = strings .Replace (CharacterInformationData .Name , localTradedString , "" , - 1 )
233
232
}
234
- } else if subma1 [ 0 ][ 1 ] == "Former Names" {
233
+ case "Former Names" :
235
234
CharacterInformationData .FormerNames = strings .Split (subma1 [0 ][2 ], ", " )
236
- } else if subma1 [ 0 ][ 1 ] == "Sex" {
235
+ case "Sex" :
237
236
CharacterInformationData .Sex = subma1 [0 ][2 ]
238
- } else if subma1 [ 0 ][ 1 ] == "Title" {
237
+ case "Title" :
239
238
regex1t := regexp .MustCompile (`(.*) \(([0-9]+).*` )
240
239
subma1t := regex1t .FindAllStringSubmatch (subma1 [0 ][2 ], - 1 )
241
240
CharacterInformationData .Title = subma1t [0 ][1 ]
242
241
CharacterInformationData .UnlockedTitles = TibiadataStringToIntegerV3 (subma1t [0 ][2 ])
243
- } else if subma1 [ 0 ][ 1 ] == "Vocation" {
242
+ case "Vocation" :
244
243
CharacterInformationData .Vocation = subma1 [0 ][2 ]
245
- } else if subma1 [ 0 ][ 1 ] == "Level" {
244
+ case "Level" :
246
245
CharacterInformationData .Level = TibiadataStringToIntegerV3 (subma1 [0 ][2 ])
247
- } else if subma1 [ 0 ][ 1 ] == "Achievement Points" {
246
+ case "Achievement Points" :
248
247
CharacterInformationData .AchievementPoints = TibiadataStringToIntegerV3 (subma1 [0 ][2 ])
249
- } else if subma1 [ 0 ][ 1 ] == "World" {
248
+ case "World" :
250
249
CharacterInformationData .World = subma1 [0 ][2 ]
251
- } else if subma1 [ 0 ][ 1 ] == "Former World" {
250
+ case "Former World" :
252
251
CharacterInformationData .FormerWorlds = strings .Split (subma1 [0 ][2 ], ", " )
253
- } else if subma1 [ 0 ][ 1 ] == "Residence" {
252
+ case "Residence" :
254
253
CharacterInformationData .Residence = subma1 [0 ][2 ]
255
- } else if strings .Contains (subma1 [0 ][1 ], "Account" ) && strings .Contains (subma1 [0 ][1 ], "Status" ) {
256
- // } else if subma1[0][1] == "Account Status" {
254
+ case "Account Status" :
257
255
CharacterInformationData .AccountStatus = subma1 [0 ][2 ]
258
- } else if subma1 [ 0 ][ 1 ] == "Married To" {
256
+ case "Married To" :
259
257
CharacterInformationData .MarriedTo = TibiadataRemoveURLsV3 (subma1 [0 ][2 ])
260
- } else if subma1 [ 0 ][ 1 ] == "House" {
258
+ case "House" :
261
259
regex1h := regexp .MustCompile (`.*houseid=([0-9]+).*character=.*>(.*)</a> \((.*)\) is paid until (.*)` )
262
260
subma1h := regex1h .FindAllStringSubmatch (subma1 [0 ][2 ], - 1 )
263
261
CharacterInformationData .Houses = append (CharacterInformationData .Houses , Houses {
@@ -266,36 +264,31 @@ func TibiaCharactersCharacterV3(c *gin.Context) {
266
264
Paid : TibiadataDateV3 (subma1h [0 ][4 ]),
267
265
HouseID : TibiadataStringToIntegerV3 (subma1h [0 ][1 ]),
268
266
})
269
- } else if strings .Contains (subma1 [0 ][1 ], "Guild" ) && strings .Contains (subma1 [0 ][1 ], "Membership" ) {
270
- // } else if subma1[0][1] == "Guild Membership" {
267
+ case "Guild Membership" :
271
268
Tmp := strings .Split (subma1 [0 ][2 ], " of the <a href=" )
272
269
CharacterInformationData .Guild .Rank = Tmp [0 ]
273
270
CharacterInformationData .Guild .GuildName = TibiadataRemoveURLsV3 ("<a href=" + Tmp [1 ])
274
- } else if subma1 [ 0 ][ 1 ] == "Last Login" {
271
+ case "Last Login" :
275
272
if subma1 [0 ][2 ] != "never logged in" {
276
273
CharacterInformationData .LastLogin = TibiadataDatetimeV3 (subma1 [0 ][2 ])
277
274
}
278
- } else if subma1 [ 0 ][ 1 ] == "Comment" {
275
+ case "Comment" :
279
276
CharacterInformationData .Comment = strings .ReplaceAll (subma1 [0 ][2 ], "<br/>" , "\n " )
280
- } else if subma1 [ 0 ][ 1 ] == "Loyalty Title" {
277
+ case "Loyalty Title" :
281
278
AccountInformationData .LoyaltyTitle = subma1 [0 ][2 ]
282
- } else if subma1 [ 0 ][ 1 ] == "Created" {
279
+ case "Created" :
283
280
AccountInformationData .Created = TibiadataDatetimeV3 (subma1 [0 ][2 ])
284
- } else if subma1 [ 0 ][ 1 ] == "Position" {
281
+ case "Position" :
285
282
TmpPosition := strings .Split (subma1 [0 ][2 ], "<" )
286
283
AccountInformationData .Position = strings .TrimSpace (TmpPosition [0 ])
287
- } else {
284
+ default :
288
285
log .Println ("LEFT OVER: `" + subma1 [0 ][1 ] + "` = `" + subma1 [0 ][2 ] + "`" )
289
286
}
290
-
291
287
}
292
-
293
288
})
294
-
295
- } else if CharacterSection == "accountbadges" {
289
+ case "accountbadges" :
296
290
// Running query over each tr in list
297
291
CharacterDivQuery .Find (".TableContentContainer tr td" ).Each (func (index int , s * goquery.Selection ) {
298
-
299
292
// Storing HTML into CharacterListHTML
300
293
CharacterListHTML , err := s .Html ()
301
294
if err != nil {
@@ -315,11 +308,9 @@ func TibiaCharactersCharacterV3(c *gin.Context) {
315
308
Description : subma1 [0 ][2 ],
316
309
})
317
310
})
318
-
319
- } else if CharacterSection == "accountachievements" {
311
+ case "accountachievements" :
320
312
// Running query over each tr in list
321
313
CharacterDivQuery .Find (localDivQueryString ).Each (func (index int , s * goquery.Selection ) {
322
-
323
314
// Storing HTML into CharacterListHTML
324
315
CharacterListHTML , err := s .Html ()
325
316
if err != nil {
@@ -349,11 +340,9 @@ func TibiaCharactersCharacterV3(c *gin.Context) {
349
340
}
350
341
351
342
})
352
-
353
- } else if CharacterSection == "characterdeaths" {
343
+ case "characterdeaths" :
354
344
// Running query over each tr in list
355
345
CharacterDivQuery .Find (localDivQueryString ).Each (func (index int , s * goquery.Selection ) {
356
-
357
346
// Storing HTML into CharacterListHTML
358
347
CharacterListHTML , err := s .Html ()
359
348
if err != nil {
@@ -439,15 +428,11 @@ func TibiaCharactersCharacterV3(c *gin.Context) {
439
428
Assists : DeathAssists ,
440
429
Reason : ReasonString ,
441
430
})
442
-
443
431
}
444
-
445
432
})
446
-
447
- } else if CharacterSection == "characters" {
433
+ case "characters" :
448
434
// Running query over each tr in character list
449
435
CharacterDivQuery .Find (localDivQueryString ).Each (func (index int , s * goquery.Selection ) {
450
-
451
436
// Storing HTML into CharacterListHTML
452
437
CharacterListHTML , err := s .Html ()
453
438
if err != nil {
@@ -462,7 +447,6 @@ func TibiaCharactersCharacterV3(c *gin.Context) {
462
447
subma1 := regex1 .FindAllStringSubmatch (CharacterListHTML , - 1 )
463
448
464
449
if len (subma1 ) > 0 {
465
-
466
450
TmpCharacterName := subma1 [0 ][1 ]
467
451
468
452
var TmpTraded bool
@@ -501,10 +485,8 @@ func TibiaCharactersCharacterV3(c *gin.Context) {
501
485
Traded : TmpTraded ,
502
486
})
503
487
}
504
-
505
488
})
506
489
}
507
-
508
490
})
509
491
510
492
//
0 commit comments