From 032e6fd7da51ac141ece096ed89198964ee66d25 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Fri, 1 Apr 2022 19:34:30 -0500 Subject: [PATCH] Nitter: Improving tweets preview, metadata and collections management. --- .../NitterUser.class/instance/getMessages.st | 7 ++++++- .../Tweet.class/instance/asCardElement.st | 2 +- .../Tweet.class/instance/fromNitterRssItem..st | 2 +- Socialmetrica.package/Tweet.class/instance/printOn..st | 2 +- Socialmetrica.package/Tweet.class/instance/textPreview.st | 6 ++++++ .../TweetsCollection.class/instance/dataStore.st | 3 +++ .../TweetsCollection.class/instance/query..st | 6 ++++++ .../TweetsCollection.class/instance/query.st | 3 +++ .../TweetsCollection.class/instance/queryParameters.st | 3 +++ .../TweetsCollection.class/instance/store.st | 7 +++++++ .../TweetsCollection.class/properties.json | 3 ++- 11 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 Socialmetrica.package/Tweet.class/instance/textPreview.st create mode 100644 Socialmetrica.package/TweetsCollection.class/instance/dataStore.st create mode 100644 Socialmetrica.package/TweetsCollection.class/instance/query..st create mode 100644 Socialmetrica.package/TweetsCollection.class/instance/query.st create mode 100644 Socialmetrica.package/TweetsCollection.class/instance/queryParameters.st create mode 100644 Socialmetrica.package/TweetsCollection.class/instance/store.st diff --git a/Socialmetrica.package/NitterUser.class/instance/getMessages.st b/Socialmetrica.package/NitterUser.class/instance/getMessages.st index 71f2715..70dad77 100644 --- a/Socialmetrica.package/NitterUser.class/instance/getMessages.st +++ b/Socialmetrica.package/NitterUser.class/instance/getMessages.st @@ -1,8 +1,13 @@ accessing getMessages - | lastTweetsRaw lastTweets | + | lastTweetsRaw customQuery lastTweets | lastTweetsRaw := self rssFeed xmlDocument xpath: '//item'. lastTweets := TweetsCollection new. + customQuery := Dictionary new + at: 'parameters' put: self; + at: 'date' put: DateAndTime now; + yourself. + lastTweets query: customQuery. lastTweetsRaw do: [ :rssTweet | lastTweets add: ((Tweet new fromNitterRssItem: rssTweet )) ]. diff --git a/Socialmetrica.package/Tweet.class/instance/asCardElement.st b/Socialmetrica.package/Tweet.class/instance/asCardElement.st index 7998aa3..d41f2aa 100644 --- a/Socialmetrica.package/Tweet.class/instance/asCardElement.st +++ b/Socialmetrica.package/Tweet.class/instance/asCardElement.st @@ -9,7 +9,7 @@ asCardElement anEditor := BrEditor new aptitude: BrGlamorousRegularEditorAptitude new + aModeLook; - text: self text; + text: self textPreview; vFitContent. textInfoPane := BrVerticalPane new diff --git a/Socialmetrica.package/Tweet.class/instance/fromNitterRssItem..st b/Socialmetrica.package/Tweet.class/instance/fromNitterRssItem..st index 7abd0a3..3245508 100644 --- a/Socialmetrica.package/Tweet.class/instance/fromNitterRssItem..st +++ b/Socialmetrica.package/Tweet.class/instance/fromNitterRssItem..st @@ -5,5 +5,5 @@ fromNitterRssItem: xmlItem user := NitterUser new userName: author . created := (xmlItem xpath: 'pubDate') stringValue. - text := (XMLHTMLParser on: (xmlItem xpath: 'description') stringValue) parseDocument stringValue. + text := (xmlItem xpath: 'description') stringValue. id := ((xmlItem xpath: 'guid') stringValue splitOn: '/') last copyReplaceAll: '#m' with: '' \ No newline at end of file diff --git a/Socialmetrica.package/Tweet.class/instance/printOn..st b/Socialmetrica.package/Tweet.class/instance/printOn..st index eacd230..5739e4d 100644 --- a/Socialmetrica.package/Tweet.class/instance/printOn..st +++ b/Socialmetrica.package/Tweet.class/instance/printOn..st @@ -2,4 +2,4 @@ accessing printOn: aStream super printOn: aStream. aStream - nextPutAll: '( ',self text ,' )' \ No newline at end of file + nextPutAll: '( ',self textPreview ,' )' \ No newline at end of file diff --git a/Socialmetrica.package/Tweet.class/instance/textPreview.st b/Socialmetrica.package/Tweet.class/instance/textPreview.st new file mode 100644 index 0000000..1955dc5 --- /dev/null +++ b/Socialmetrica.package/Tweet.class/instance/textPreview.st @@ -0,0 +1,6 @@ +accessing +textPreview + "I'm a utility method to improve the way text is rendered accordin to if it comes from + Nitter or Twitter." + ^ (XMLHTMLParser on: self text) parseDocument stringValue + \ No newline at end of file diff --git a/Socialmetrica.package/TweetsCollection.class/instance/dataStore.st b/Socialmetrica.package/TweetsCollection.class/instance/dataStore.st new file mode 100644 index 0000000..d21a79d --- /dev/null +++ b/Socialmetrica.package/TweetsCollection.class/instance/dataStore.st @@ -0,0 +1,3 @@ +accessing +dataStore + ^ (FileLocator userData / 'Socialmetrica') ensureCreateDirectory \ No newline at end of file diff --git a/Socialmetrica.package/TweetsCollection.class/instance/query..st b/Socialmetrica.package/TweetsCollection.class/instance/query..st new file mode 100644 index 0000000..53446cf --- /dev/null +++ b/Socialmetrica.package/TweetsCollection.class/instance/query..st @@ -0,0 +1,6 @@ +accessing +query: aDictionary + "The dictionary has two keys: the query parameter(s) itself + and the date when the query was executed. + Such information is used to store/serialize query results outside of the image." + query := aDictionary \ No newline at end of file diff --git a/Socialmetrica.package/TweetsCollection.class/instance/query.st b/Socialmetrica.package/TweetsCollection.class/instance/query.st new file mode 100644 index 0000000..8dec2b7 --- /dev/null +++ b/Socialmetrica.package/TweetsCollection.class/instance/query.st @@ -0,0 +1,3 @@ +accessing +query + ^ query \ No newline at end of file diff --git a/Socialmetrica.package/TweetsCollection.class/instance/queryParameters.st b/Socialmetrica.package/TweetsCollection.class/instance/queryParameters.st new file mode 100644 index 0000000..849a396 --- /dev/null +++ b/Socialmetrica.package/TweetsCollection.class/instance/queryParameters.st @@ -0,0 +1,3 @@ +accessing +queryParameters + ^ self query at: 'parameters' \ No newline at end of file diff --git a/Socialmetrica.package/TweetsCollection.class/instance/store.st b/Socialmetrica.package/TweetsCollection.class/instance/store.st new file mode 100644 index 0000000..aa1fcbc --- /dev/null +++ b/Socialmetrica.package/TweetsCollection.class/instance/store.st @@ -0,0 +1,7 @@ +accessing +store + | localFolder parameters | + parameters := self queryParameters . + parameters class = NitterUser ifFalse: [ ^ self ]. + ^ localFolder := (self dataStore / parameters userName) ensureCreateDirectory. + \ No newline at end of file diff --git a/Socialmetrica.package/TweetsCollection.class/properties.json b/Socialmetrica.package/TweetsCollection.class/properties.json index 1758ab4..d31a7b1 100644 --- a/Socialmetrica.package/TweetsCollection.class/properties.json +++ b/Socialmetrica.package/TweetsCollection.class/properties.json @@ -6,7 +6,8 @@ "pools" : [ ], "classvars" : [ ], "instvars" : [ - "tweets" + "tweets", + "query" ], "name" : "TweetsCollection", "type" : "normal"