Code review: Modularization.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2022-04-11 12:11:10 -05:00
parent 65c36e924c
commit bc168c4f0a
4 changed files with 34 additions and 27 deletions

View File

@ -1,4 +1,4 @@
accessing accessing
getMessages getMessages
self getLocalMessages ifNil: [ self getRemoteMessages ]. self getLocalMessages ifNil: [ self getRemoteMessagesFromRss ].
^ self tweets ^ self tweets

View File

@ -1,5 +1,5 @@
accessing accessing
getRemoteMessages getRemoteMessagesFromRss
| customQuery lastTweetsRaw lastTweets | | customQuery lastTweetsRaw lastTweets |
lastTweetsRaw := self rssFeed xmlDocument xpath: '//item'. lastTweetsRaw := self rssFeed xmlDocument xpath: '//item'.

View File

@ -0,0 +1,5 @@
accessing
lastTweetsFromHtml
^ (self documentTree xpath: '//div[@class="timeline-item "]')
asOrderedCollection collect: [ :xmlElement | xmlElement postCopy ]

View File

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