Improving urls for load more tweets and removing unnecessary method. ref 5b169c4ebf

This commit is contained in:
ruidajo 2022-04-07 14:17:17 -05:00
parent 610c8e4ca1
commit b198bde247
3 changed files with 41 additions and 17 deletions

View File

@ -1,5 +0,0 @@
accessing
defaultConfig
self config: { 'folder' -> (FileLocator userData / 'Socialmetrica' / self userName) } asDictionary.
^ self config

View File

@ -1,18 +1,35 @@
accessing accessing
numberOfURLsForLoadingTweets: number numberOfURLsForLoadingTweets: number
| collectionURLs count asURLs | | collectionURLs count asURLs urlAndTweets |
collectionURLs := { number = 1 ifTrue: [ ^ self ].
self userNameLink .
(self userNameLink, ((self documentTree xPath: '//a[.="Load more"]') @ 'href') stringValue) .} asOrderedCollection.
number <= 2 ifTrue: [ ^ collectionURLs ]. urlAndTweets := OrderedDictionary new.
count := 2. collectionURLs := { self userNameLink .}asOrderedCollection.
(number-count) timesRepeat: [ | tempDoc |
tempDoc := XMLHTMLParser parse: (collectionURLs at: count) asUrl retrieveContents. urlAndTweets
collectionURLs at: 'tweets'
add: (self userNameLink, put: ((self documentTree xpath: '//div[@class="timeline-item "]')asOrderedCollection collect: [ :xmlElement | xmlElement postCopy]).
((tempDoc xPath: '//a[.="Load more"]') @ 'href') stringValue).
count := 1.
(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.
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 ]. count := count+1 ].
asURLs := collectionURLs collect: [ :string | string asUrl ]. asURLs := collectionURLs collect: [ :string | string asUrl ].
^ asURLs.
urlAndTweets at: 'urls' put: asURLs.
^ urlAndTweets.

View File

@ -0,0 +1,12 @@
accessing
fromNitterTimelineItem: xmlItem
| author authorAndId |
authorAndId := (((xmlItem xpath: '//a[@class="tweet-link"]')
asString splitOn: 'href="' ) second splitOn: '/') reject: [ :i | i isEmpty or: [i = '>)']].
author := authorAndId first.
user := NitterUser new
userName: author .
"created := (xmlItem xpath: 'pubDate') stringValue.
text := (xmlItem xpath: 'description') stringValue."
id := authorAndId last copyReplaceAll: '#m"' with: ''.
authorId := self user id.