Socialmetrica/Socialmetrica.package/NitterUser.class/instance/storeContents.st

26 lines
933 B
Smalltalk
Raw Normal View History

accessing
storeContents
| objectString directory tempFile oldFile dehidratated |
dehidratated := self copy.
dehidratated tweets: nil.
objectString := STON toStringPretty: dehidratated.
directory := (FileLocator userData / 'Socialmetrica' / self userName) ensureCreateDirectory.
oldFile := directory / self userName, 'ston'.
oldFile exists ifFalse: [
^ MarkupFile exportAsFileOn: oldFile containing: objectString ].
tempFile := MarkupFile
exportAsFileOn: FileLocator temp / self userName, 'ston'
containing: objectString.
(tempFile contents hash hex = oldFile contents hash hex) ifFalse: [
oldFile copyTo: directory /
(oldFile basenameWithoutExtension , '-',
('-' join:((oldFile creationTime asLocalStringYMDHM) splitOn: ' ')),
'.ston').
oldFile ensureDelete.
^ { 'Profile changed' -> (tempFile moveTo: oldFile)} asDictionary ].
^ { 'Same Profile' -> oldFile } asDictionary.