Socialmetrica/Socialmetrica.package/NitterUser.class/instance/numberOfURLsForLoadingTweets..st

37 lines
1.0 KiB
Smalltalk
Raw Normal View History

accessing
numberOfURLsForLoadingTweets: number
| collectionURLs count asURLs urlAndTweets |
number = 1 ifTrue: [ ^ self ].
2022-04-11 17:11:10 +00:00
urlAndTweets := OrderedDictionary new.
2022-04-11 17:11:10 +00:00
collectionURLs := { self userNameLink } asOrderedCollection.
urlAndTweets at: 'tweets' put: self lastTweetsFromHtml.
count := 1.
2022-04-11 17:11:10 +00:00
number - count timesRepeat: [
| tempDoc docTree urlString |
tempDoc := XMLHTMLParser parse:
(collectionURLs at: count) asUrl retrieveContents.
urlString := self userNameLink
,
((tempDoc xPath: '//a[.="Load more"]') @ 'href')
stringValue.
docTree := XMLHTMLParser parse: urlString asUrl retrieveContents.
2022-04-11 17:11:10 +00:00
collectionURLs add: urlString.
urlAndTweets
at: 'tweets-' , (urlString splitOn: 'cursor=') second
put:
((docTree xpath: '//div[@class="timeline-item "]')
asOrderedCollection collect: [ :xmlElement |
xmlElement postCopy ]).
count := count + 1 ].
asURLs := collectionURLs collect: [ :string | string asUrl ].
2022-04-11 17:11:10 +00:00
urlAndTweets at: 'urls' put: asURLs.
2022-04-11 17:11:10 +00:00
^ urlAndTweets