From 3315efd807969fbc203d2afd4262a07b1622936d Mon Sep 17 00:00:00 2001 From: ruidajo Date: Mon, 16 Sep 2024 20:20:26 -0500 Subject: [PATCH] Creating Instagram local class and improving instagram downloader. --- Instagram/InstagramDownloader.class.st | 20 ++++++-- Instagram/InstagramLocal.class.st | 63 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 Instagram/InstagramLocal.class.st diff --git a/Instagram/InstagramDownloader.class.st b/Instagram/InstagramDownloader.class.st index f0fda2c..b2b190c 100644 --- a/Instagram/InstagramDownloader.class.st +++ b/Instagram/InstagramDownloader.class.st @@ -8,16 +8,25 @@ Class { #category : #Instagram } +{ #category : #accessing } +InstagramDownloader >> asInstagramLocal [ + ^ InstagramLocal new profiles: self profiles; + rootDir: self profiles values first parent +] + { #category : #'as yet unclassified' } InstagramDownloader >> downloadProfile: anInstProfileName [ - | profiles | - profiles := (FileLocator documents / 'InstagramDownloader' / 'Profiles') ensureCreateDirectory. + | tempProfiles | + tempProfiles := (FileLocator documents / 'InstagramDownloader' / 'Profiles') + ensureCreateDirectory. ^ GtSubprocessWithInMemoryOutput new - workingDirectory: profiles; + workingDirectory: tempProfiles; command: bin fullName; arguments: {anInstProfileName. '--no-videos'. - '--no-compress-json'}; + '--no-compress-json'. + '--filename-pattern'. + '{profile}-{date_utc}-UTC-code:{shortcode}'}; runAndWait; stdout ] @@ -43,7 +52,8 @@ InstagramDownloader >> loadDefault [ | temp | temp := FileLocator documents / 'InstagramDownloader'. bin := temp / 'bin' / 'instaloader'. - profiles := temp / 'Profiles' + profiles := ((temp / 'Profiles') children + collect: [ :dir | dir basename -> dir ]) asDictionary ] { #category : #'as yet unclassified' } diff --git a/Instagram/InstagramLocal.class.st b/Instagram/InstagramLocal.class.st new file mode 100644 index 0000000..ae0dd5a --- /dev/null +++ b/Instagram/InstagramLocal.class.st @@ -0,0 +1,63 @@ +Class { + #name : #InstagramLocal, + #superclass : #Object, + #instVars : [ + 'profiles', + 'rootDir', + 'posts' + ], + #category : #Instagram +} + +{ #category : #'as yet unclassified' } +InstagramLocal >> postsProcessed [ + | temp shortcodes | + temp := Dictionary new. + shortcodes := OrderedCollection new. + self profiles + keysAndValuesDo: [ :k :v | + | sel col | + sel := v children + select: [ :file | file extension = 'json' and: [ file basename includesSubstring: 'code:' ] ]. + col := sel + collect: [ :file | | tempShortcode | + tempShortcode := ('code:' split: file basenameWithoutExtension) second. + shortcodes add: tempShortcode. + (v / ('Post-' , tempShortcode )) + ensureCreateDirectory ]. + temp at: k put: col. ]. + ^ { temp . shortcodes } +] + +{ #category : #accessing } +InstagramLocal >> postsTiddlers [ + | temp jsons| + temp := OrderedCollection new. + self profiles + valuesDo: [ :v | + temp + add: (v children + select: [ :file | file extension = 'json' and: [ file basename includesSubstring: 'code:' ] ]) ]. + jsons := temp flatten collect: [ :post | STONJSON fromString: post contents ]. + ^ jsons collect: [:json | Tiddler nowLocal ] +] + +{ #category : #accessing } +InstagramLocal >> profiles [ + ^ profiles +] + +{ #category : #accessing } +InstagramLocal >> profiles: aCollectionProfiles [ + profiles := aCollectionProfiles +] + +{ #category : #accessing } +InstagramLocal >> rootDir [ + ^ rootDir +] + +{ #category : #accessing } +InstagramLocal >> rootDir: anObject [ + rootDir := anObject +]