Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/TibiaNewsV3.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ type News struct {
ContentHTML string `json:"content_html"`
}

//
// The base
type NewsResponse struct {
News News `json:"news"`
Information Information `json:"information"`
}

var (
martelRegex = regexp.MustCompile(`<img src=\"https:\/\/static\.tibia\.com\/images\/global\/letters\/letter_martel_(.)\.gif\" ([^\/>]+..)`)
)
var martelRegex = regexp.MustCompile(`<img src=\"https:\/\/static\.tibia\.com\/images\/global\/letters\/letter_martel_(.)\.gif\" ([^\/>]+..)`)

func TibiaNewsV3Impl(NewsID int, rawUrl string, BoxContentHTML string) NewsResponse {
// Declaring vars for later use..
Expand All @@ -49,7 +46,6 @@ func TibiaNewsV3Impl(NewsID int, rawUrl string, BoxContentHTML string) NewsRespo
NewsData.TibiaURL = rawUrl

ReaderHTML.Find(".NewsHeadline").Each(func(index int, s *goquery.Selection) {

// getting category by image src
CategoryImg, _ := s.Find("img").Attr("src")
NewsData.Category = TibiaDataGetNewsCategory(CategoryImg)
Expand All @@ -70,12 +66,16 @@ func TibiaNewsV3Impl(NewsID int, rawUrl string, BoxContentHTML string) NewsRespo
})

ReaderHTML.Find(".NewsTableContainer").Each(func(index int, s *goquery.Selection) {

// checking if its a ticker..
if NewsData.Type == "ticker" {
tmp1 = s.Find("p")
NewsData.Content = tmp1.Text()
NewsData.ContentHTML, _ = tmp1.Html()
if tmp1.Text() == "" {
NewsData.Content = s.Text()
NewsData.ContentHTML, _ = s.Html()
} else {
NewsData.Content = tmp1.Text()
NewsData.ContentHTML, _ = tmp1.Html()
}
} else {
// getting html
tmp2, _ = s.First().Html()
Expand Down
20 changes: 20 additions & 0 deletions src/TibiaNewsV3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ func TestNews6512(t *testing.T) {
assert.Equal("<a href=\"https://tibiadata.com\" target=\"_blank\" rel=\"noopener noreferrer\" rel=\"noopener\">TibiaData.com</a> has some news to share! First of all, they invite you to participate in their <a href=\"https://tibiadata.com/2021/07/join-tibiadata-on-discord/\" target=\"_blank\" rel=\"noopener noreferrer\" rel=\"noopener\">Discord Server</a>. Further, they are now present on <a href=\"https://tibiadata.com/2021/12/tibiadata-has-gone-open-source/\" target=\"_blank\" rel=\"noopener noreferrer\" rel=\"noopener\">GitHub</a>. They are working on their <a href=\"https://tibiadata.com/doc-api-v3/v3-beta/\" target=\"_blank\" rel=\"noopener noreferrer\" rel=\"noopener\">v3</a>, which is still in beta. If you are interested in such things, head on over there to see what is cooking.", newsArticleJson.News.ContentHTML)
}

func TestNews504(t *testing.T) {
data, err := os.ReadFile("../testdata/news/archive/504.html")
if err != nil {
t.Errorf("File reading error: %s", err)
return
}

newsArticleJson := TibiaNewsV3Impl(504, "https://www.tibia.com/news/?subtopic=newsarchive&id=504", string(data))
assert := assert.New(t)

assert.Equal(504, newsArticleJson.News.ID)
assert.Equal("2007-04-27", newsArticleJson.News.Date)
assert.Empty(newsArticleJson.News.Title)
assert.Equal("community", newsArticleJson.News.Category)
assert.Equal("ticker", newsArticleJson.News.Type)
assert.Equal("https://www.tibia.com/news/?subtopic=newsarchive&id=504", newsArticleJson.News.TibiaURL)
assert.Equal("A new feedback form has been released today. Help us to find out which websites and magazines are popular in your country by filling out the new questionnaire. In our current poll we are curious about your occupation.", newsArticleJson.News.Content)
assert.Equal("<br/>A new feedback form has been released today. Help us to find out which websites and magazines are popular in your country by filling out the new questionnaire. In our current poll we are curious about your occupation.", newsArticleJson.News.ContentHTML)
}

func TestNews6481(t *testing.T) {
data, err := os.ReadFile("../testdata/news/archive/6481.html")
if err != nil {
Expand Down
Loading