Fix unusual bug when scraping tweets which only happens if the tweet has a link and the text is exactly 22 chars long

This commit is contained in:
Alessio 2024-05-05 11:59:58 -07:00
parent a0a32d0fb8
commit 5cbf96f379

View File

@ -202,6 +202,10 @@ func (t *APITweet) NormalizeContent() {
// Handle short links showing up at ends of tweets // Handle short links showing up at ends of tweets
for _, url := range t.Entities.URLs { for _, url := range t.Entities.URLs {
index := strings.Index(t.FullText, url.ShortenedUrl) index := strings.Index(t.FullText, url.ShortenedUrl)
if index < 0 {
// It's not in the text
continue
}
if index == (len(t.FullText) - len(url.ShortenedUrl)) { if index == (len(t.FullText) - len(url.ShortenedUrl)) {
t.FullText = strings.TrimSpace(t.FullText[0:index]) t.FullText = strings.TrimSpace(t.FullText[0:index])
} }