From f6b14c086dad1cced43f92a02e37a05ecb0282aa Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sun, 2 Jan 2022 19:01:09 -0500 Subject: [PATCH] Improving Nitter data extraction and rendering. --- .../NitterUser.class/instance/url.st | 4 ++++ .../TwitterUser.class/instance/asCardElement.st | 12 +++++++++--- .../instance/fromNitterProfile..st | 2 +- .../TwitterUser.class/instance/profileImage.st | 16 +++------------- .../TwitterUser.class/instance/url.st | 3 +++ 5 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 Datanalitica.package/NitterUser.class/instance/url.st create mode 100644 Datanalitica.package/TwitterUser.class/instance/url.st diff --git a/Datanalitica.package/NitterUser.class/instance/url.st b/Datanalitica.package/NitterUser.class/instance/url.st new file mode 100644 index 0000000..0a8ea9d --- /dev/null +++ b/Datanalitica.package/NitterUser.class/instance/url.st @@ -0,0 +1,4 @@ +accessing +url + ^ url ifNil: [ + url := ((self documentTree xpath: '//div[@class="profile-website"]') // 'a' @@ 'href') first asUrl] \ No newline at end of file diff --git a/Datanalitica.package/TwitterUser.class/instance/asCardElement.st b/Datanalitica.package/TwitterUser.class/instance/asCardElement.st index 8a2ac98..cba62f8 100644 --- a/Datanalitica.package/TwitterUser.class/instance/asCardElement.st +++ b/Datanalitica.package/TwitterUser.class/instance/asCardElement.st @@ -1,6 +1,6 @@ accessing asCardElement - | aModeLook anEditor textInfoPane buttonsPane | + | aModeLook anEditor textInfoPane buttonsPane webpageButton | aModeLook := BrEditorModeAptitude new editableFocused: [ :aWidget | aWidget border: (BlBorder paint: BrGlamorousColors focusedEditorBorderColor width: 1) ]; @@ -11,6 +11,11 @@ asCardElement aptitude: BrGlamorousRegularEditorAptitude new + aModeLook; text: self description; vFitContent. + + webpageButton := BrButton new + aptitude: BrGlamorousButtonWithLabelAptitude new; + label: (self url asString copyReplaceAll: self url scheme, '://' with: '') allButLast; + action: [ WebBrowser openOn: self url asString ]. textInfoPane := BrVerticalPane new hMatchParent; @@ -26,8 +31,9 @@ asCardElement beLargeSize); addChild: (BrLabel new aptitude: BrGlamorousLabelAptitude; - text: 'Joined: ' , self createdAtShorted ); - addChild: anEditor. + text: 'Joined: ' , self createdAtShorted ). + self url ifNotNil: [textInfoPane addChild: webpageButton]. + textInfoPane addChild: anEditor. buttonsPane := BrHorizontalPane new fitContent; cellSpacing: 5; diff --git a/Datanalitica.package/TwitterUser.class/instance/fromNitterProfile..st b/Datanalitica.package/TwitterUser.class/instance/fromNitterProfile..st index f5bb9ef..b8e34b5 100644 --- a/Datanalitica.package/TwitterUser.class/instance/fromNitterProfile..st +++ b/Datanalitica.package/TwitterUser.class/instance/fromNitterProfile..st @@ -3,7 +3,7 @@ fromNitterProfile: userNameString | nitterUser joinDateString | nitterUser := NitterUser new userName: userNameString. name := nitterUser name. - userName := NitterUser new userName: userNameString. + userName := nitterUser userName. "((title splitOn: '/') second trimmed) allButFirst." "<--This should go to a test." profileImageUrl := nitterUser profileImageUrl. description := nitterUser description. diff --git a/Datanalitica.package/TwitterUser.class/instance/profileImage.st b/Datanalitica.package/TwitterUser.class/instance/profileImage.st index 06a59e6..686ba94 100644 --- a/Datanalitica.package/TwitterUser.class/instance/profileImage.st +++ b/Datanalitica.package/TwitterUser.class/instance/profileImage.st @@ -1,17 +1,7 @@ accessing profileImage - | response | - response := ZnClient new url: (self profileImageUrl); get; response. - response contentType = ZnMimeType imageJpeg - ifTrue: [ | imageTemp | - imageTemp := [ JPEGReadWriter gtFromBuffer: response contents ]. + ^ BlUrlImageElement url: self profileImageUrl + "The previous version has something like imageTemp on: Error do: [ ^ GtABContact new avatar ]. ^ imageTemp value asElement - ]. - response contentType = ZnMimeType imagePng - ifTrue: [ | imageTemp | - imageTemp := [ PNGReadWriter gtFromBuffer: response contents ]. - imageTemp on: Error do: [ ^ GtABContact new avatar ]. - ^ imageTemp value asElement - ]. - ^ BlElement new background: Color gray \ No newline at end of file + Should a generic avatar be reimplemented?" \ No newline at end of file diff --git a/Datanalitica.package/TwitterUser.class/instance/url.st b/Datanalitica.package/TwitterUser.class/instance/url.st new file mode 100644 index 0000000..958fa17 --- /dev/null +++ b/Datanalitica.package/TwitterUser.class/instance/url.st @@ -0,0 +1,3 @@ +accessing +url + ^ url \ No newline at end of file