workaround newly js only twitter site for hoot:

This commit is contained in:
Ted Unangst 2020-06-30 16:37:35 -04:00
parent edcc6d7c54
commit 0f648d1286
2 changed files with 16 additions and 7 deletions

View File

@ -2,6 +2,8 @@ changelog
=== next === next
+ Workaround js only twitter for hoot: feature.
++ Boing boom tschak chonky chatter. ++ Boing boom tschak chonky chatter.
+ Quote unquote reliability improvements. + Quote unquote reliability improvements.

17
hoot.go
View File

@ -29,8 +29,8 @@ import (
"humungus.tedunangst.com/r/webs/htfilter" "humungus.tedunangst.com/r/webs/htfilter"
) )
var tweetsel = cascadia.MustCompile("p.tweet-text") var tweetsel = cascadia.MustCompile("div.tweet-text")
var linksel = cascadia.MustCompile(".time a.tweet-timestamp") var linksel = cascadia.MustCompile("td.timestamp a")
var replyingto = cascadia.MustCompile(".ReplyingToContextBelowAuthor") var replyingto = cascadia.MustCompile(".ReplyingToContextBelowAuthor")
var authorregex = regexp.MustCompile("twitter.com/([^/]+)") var authorregex = regexp.MustCompile("twitter.com/([^/]+)")
@ -44,6 +44,8 @@ func hootextractor(r io.Reader, url string, seen map[string]bool) string {
} }
divs := tweetsel.MatchAll(root) divs := tweetsel.MatchAll(root)
url = strings.Replace(url, "mobile.twitter.com", "twitter.com", -1)
var wanted string var wanted string
wantmatch := authorregex.FindStringSubmatch(url) wantmatch := authorregex.FindStringSubmatch(url)
if len(wantmatch) == 2 { if len(wantmatch) == 2 {
@ -56,21 +58,25 @@ func hootextractor(r io.Reader, url string, seen map[string]bool) string {
htf.Imager = func(node *html.Node) string { htf.Imager = func(node *html.Node) string {
return "" return ""
} }
for _, div := range divs { for i, div := range divs {
twp := div.Parent.Parent.Parent twp := div.Parent.Parent.Parent
link := url
alink := linksel.MatchFirst(twp) alink := linksel.MatchFirst(twp)
if alink == nil { if alink == nil {
if i != 0 {
log.Printf("missing link") log.Printf("missing link")
continue continue
} }
} else {
link = "https://twitter.com" + htfilter.GetAttr(alink, "href")
}
replto := replyingto.MatchFirst(twp) replto := replyingto.MatchFirst(twp)
if replto != nil { if replto != nil {
continue continue
} }
link := "https://twitter.com" + htfilter.GetAttr(alink, "href")
authormatch := authorregex.FindStringSubmatch(link) authormatch := authorregex.FindStringSubmatch(link)
if len(authormatch) < 2 { if len(authormatch) < 2 {
log.Printf("no author?") log.Printf("no author?: %s", link)
continue continue
} }
author := authormatch[1] author := authormatch[1]
@ -103,6 +109,7 @@ func hooterize(noise string) string {
url = url[1:] url = url[1:]
} }
url = strings.Replace(url, "mobile.twitter.com", "twitter.com", -1) url = strings.Replace(url, "mobile.twitter.com", "twitter.com", -1)
url = strings.Replace(url, "twitter.com", "mobile.twitter.com", -1)
log.Printf("hooterizing %s", url) log.Printf("hooterizing %s", url)
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {