From 610c8e4ca1cbf09aac9fa6293d2aeeeb4bfad78f Mon Sep 17 00:00:00 2001 From: ruidajo Date: Thu, 7 Apr 2022 11:28:18 -0500 Subject: [PATCH 1/2] Improving nitter user profile image exporter. --- .../instance/downloadProfileImage.st | 2 +- .../instance/exportProfileImageOn..st | 51 ++++++++++++++++--- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/Socialmetrica.package/NitterUser.class/instance/downloadProfileImage.st b/Socialmetrica.package/NitterUser.class/instance/downloadProfileImage.st index 0cae0dc..af43576 100644 --- a/Socialmetrica.package/NitterUser.class/instance/downloadProfileImage.st +++ b/Socialmetrica.package/NitterUser.class/instance/downloadProfileImage.st @@ -1,4 +1,4 @@ accessing downloadProfileImage - ^ self exportProfileImageOn: self folder / self userName, 'jpg' \ No newline at end of file + ^ self exportProfileImageOn: self folder / 'profile-image', 'jpg' \ No newline at end of file diff --git a/Socialmetrica.package/NitterUser.class/instance/exportProfileImageOn..st b/Socialmetrica.package/NitterUser.class/instance/exportProfileImageOn..st index fcd8fd9..a8427d5 100644 --- a/Socialmetrica.package/NitterUser.class/instance/exportProfileImageOn..st +++ b/Socialmetrica.package/NitterUser.class/instance/exportProfileImageOn..st @@ -1,11 +1,48 @@ accessing exportProfileImageOn: fileReference - | file | + | file tempFile tempFileHash fileHash | file := fileReference asFileReference. - file ensureDelete. - file exists ifFalse: [ file ensureCreateFile ]. - file binaryWriteStreamDo: [ :stream | - stream nextPutAll: profileImageUrl retrieveContents ]. - super class inform: 'Exported as: ', String cr, file fullName. - ^ file \ No newline at end of file + file exists + ifFalse: [ file ensureCreateFile. + file binaryWriteStreamDo: [ :stream | + stream nextPutAll: profileImageUrl retrieveContents ]. + super class inform: 'Exported as: ', String cr, file fullName. + ^ file] + + ifTrue: [ + tempFile := FileLocator temp / fileReference basename. + tempFile ensureCreateFile. + tempFile binaryWriteStreamDo: [ :stream | + stream nextPutAll: profileImageUrl retrieveContents. + super class + inform: 'Exported as: ', String cr, tempFile fullName. ]. + + OSSUnixSubprocess new + command: 'openssl'; + arguments: { 'dgst' . '-sha256' . file fullName}; + workingDirectory: (self folder)fullName; + redirectStdout; + redirectStderr; + runAndWaitOnExitDo: [ :process :outString | + fileHash := (outString splitOn: ' ' ) second trimmed]. + + OSSUnixSubprocess new + command: 'openssl'; + arguments: { 'dgst' . '-sha256' . tempFile fullName}; + workingDirectory: (self folder)fullName; + redirectStdout; + redirectStderr; + runAndWaitOnExitDo: [ :process :outString | + tempFileHash := (outString splitOn: ' ' ) second trimmed]. + + fileHash = tempFileHash + ifFalse: [ + file copyTo: self folder / + (file basenameWithoutExtension , '-', + ('-' join: + ((file creationTime asLocalStringYMDHM) splitOn: ' ')), '.jpg'). + file ensureDelete. + ^ { 'Profile image changed' -> + (tempFile moveTo: file)} asDictionary ]]. + ^ { 'Same Profile Image' -> file } asDictionary \ No newline at end of file From 17b39ec4ad298e3310e3d21ee8064ea8762e4b27 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Thu, 7 Apr 2022 13:33:46 -0500 Subject: [PATCH 2/2] Fixing TwitterUser id detection. --- Socialmetrica.package/NitterUser.class/instance/id.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Socialmetrica.package/NitterUser.class/instance/id.st b/Socialmetrica.package/NitterUser.class/instance/id.st index 6db6025..30d492e 100644 --- a/Socialmetrica.package/NitterUser.class/instance/id.st +++ b/Socialmetrica.package/NitterUser.class/instance/id.st @@ -1,3 +1,3 @@ accessing id - ^ id ifNil: [id := (self profileImageUrl segments select: [ :each | each asInteger class = LargePositiveInteger]) first.] \ No newline at end of file + ^ id ifNil: [ id := (self profileImageUrl segments detect: [ :each | each isAllDigits ]) ] \ No newline at end of file