Socialmetrica/Socialmetrica.package/Tweet.class/instance/fromNitterTimelineItem..st

43 lines
1.8 KiB
Smalltalk

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 ])