MCPcopy Create free account
hub / github.com/MMadmer/EpicAssetsNotifyBot / parseAssets

Function parseAssets

internal/fab/scraper.go:292–339  ·  view source on GitHub ↗
(sectionHTML string)

Source from the content-addressed store, hash-verified

290}
291
292func parseAssets(sectionHTML string) []Asset {
293 if sectionHTML == "" {
294 return nil
295 }
296
297 assets := make([]Asset, 0)
298 seenLinks := make(map[string]struct{})
299
300 for _, liMatch := range listItemPattern.FindAllStringSubmatch(sectionHTML, -1) {
301 liHTML := liMatch[1]
302 anchorMatch := anchorPattern.FindStringSubmatch(liHTML)
303 if anchorMatch == nil {
304 continue
305 }
306
307 attrs := parseAttributes(anchorMatch[1], attributePattern)
308 href := strings.TrimSpace(html.UnescapeString(attrs["href"]))
309 if !strings.HasPrefix(href, "/listings/") {
310 continue
311 }
312
313 link := "https://www.fab.com" + href
314 if _, exists := seenLinks[link]; exists {
315 continue
316 }
317 seenLinks[link] = struct{}{}
318
319 name := cleanText(stripTags(anchorMatch[2]))
320 if name == "" {
321 if ariaLabel := attrs["aria-label"]; ariaLabel != "" {
322 name = cleanText(ariaLabel)
323 }
324 }
325
326 image := ""
327 if imageMatch := imagePattern.FindStringSubmatch(liHTML); imageMatch != nil {
328 image = normalizeImageURL(strings.TrimSpace(html.UnescapeString(imageMatch[1])))
329 }
330
331 assets = append(assets, Asset{
332 Name: emptyToZero(name),
333 Link: link,
334 Image: emptyToZero(image),
335 })
336 }
337
338 return assets
339}
340
341func parseAttributes(input string, pattern *regexp.Regexp) map[string]string {
342 attributes := make(map[string]string)

Callers 1

ParseFreeAssetsFunction · 0.85

Calls 5

parseAttributesFunction · 0.85
cleanTextFunction · 0.85
stripTagsFunction · 0.85
normalizeImageURLFunction · 0.85
emptyToZeroFunction · 0.85

Tested by

no test coverage detected