Code review. Improving modularization and naming.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2022-04-11 11:42:54 -05:00
parent 89a73603a3
commit 65c36e924c
5 changed files with 58 additions and 43 deletions

View File

@ -0,0 +1,20 @@
accessing
fromNitterHtmlItem: xmlItem
| author authorAndId timeTemp |
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.
timeTemp := (((xmlItem xpath: '//span[@class="tweet-date"]') asString
splitOn: 'title="') second splitOn: '">') first.
timeTemp := ((timeTemp copyReplaceAll: ' · ' with: ' ')
copyReplaceAll: 'UTC'
with: '+00:00') asDateAndTime.
created := timeTemp.
text := (xmlItem xpath: '//div[@class="tweet-content media-body"]')
stringValue.
id := authorAndId last copyReplaceAll: '#m"' with: ''.
authorId := self user id.
self metricsFromNitterHtml: xmlItem

View File

@ -1,43 +0,0 @@
accessing
fromNitterTimelineItem: xmlItem
| author authorAndId metricsTemp timeTemp |
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 .
timeTemp := (((xmlItem xpath: '//span[@class="tweet-date"]')asString splitOn: 'title="') second splitOn: '">')first.
timeTemp := ((timeTemp copyReplaceAll: ' · ' with: ' ') copyReplaceAll: 'UTC' with: '+00:00') asDateAndTime.
created := timeTemp.
text := (xmlItem xpath: '//div[@class="tweet-content media-body"]')stringValue.
id := authorAndId last copyReplaceAll: '#m"' with: ''.
authorId := self user id.
metricsTemp := Dictionary new .
metricsTemp
at: 'comment'
put: ((((xmlItem xpath: '//div[@class="icon-container"]')
select: [ :item | item asString includesSubstring: 'comment' ])
stringValue trimmed) copyReplaceAll: ',' with: '');
at: 'retweet'
put: ((((xmlItem xpath: '//div[@class="icon-container"]')
select: [ :item | item asString includesSubstring: 'retweet' ])
stringValue trimmed) copyReplaceAll: ',' with: '');
at: 'quote'
put: ((((xmlItem xpath: '//div[@class="icon-container"]')
select: [ :item | item asString includesSubstring: 'quote' ])
stringValue trimmed) copyReplaceAll: ',' with: '');
at: 'heart'
put: ((((xmlItem xpath: '//div[@class="icon-container"]')
select: [ :item | item asString includesSubstring: 'heart' ])
stringValue trimmed) copyReplaceAll: ',' with: '').
metrics := metricsTemp.
metadata := Dictionary new.
metadata
at: 'pinned'
put: (((xmlItem xpath: '//div[@class="pinned"]') stringValue trimmed) = 'Pinned Tweet'
ifTrue: [ true ]
ifFalse: [ false ])

View File

@ -0,0 +1,4 @@
accessing
metrics: anObject
metrics := anObject

View File

@ -0,0 +1,4 @@
accessing
metrics
^ metrics ifNil: [ metrics := Dictionary new ]

View File

@ -0,0 +1,30 @@
accessing
metricsFromNitterHtml: xmlItem
self metrics
at: 'comment'
put:
(((xmlItem xpath: '//div[@class="icon-container"]') select: [ :item |
item asString includesSubstring: 'comment' ]) stringValue
trimmed copyReplaceAll: ',' with: '');
at: 'retweet'
put:
(((xmlItem xpath: '//div[@class="icon-container"]') select: [ :item |
item asString includesSubstring: 'retweet' ]) stringValue
trimmed copyReplaceAll: ',' with: '');
at: 'quote'
put:
(((xmlItem xpath: '//div[@class="icon-container"]') select: [ :item |
item asString includesSubstring: 'quote' ]) stringValue trimmed
copyReplaceAll: ','
with: '');
at: 'heart'
put:
(((xmlItem xpath: '//div[@class="icon-container"]') select: [ :item |
item asString includesSubstring: 'heart' ]) stringValue trimmed
copyReplaceAll: ','
with: '').
metadata
at: 'pinned'
put: (xmlItem xpath: '//div[@class="pinned"]') stringValue trimmed = 'Pinned Tweet'