Skip to content

Commit c59c1aa

Browse files
committed
scripts: like by location
1 parent c5a38ff commit c59c1aa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

client/src/scripts.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,35 @@ const scripts = {
9696
}
9797
},
9898

99+
like_location: {
100+
params: [
101+
{ name: 'location_name', type: 'text', labelText: 'Location name' },
102+
{ name: 'nPhotos', type: 'number', labelText: 'Number of photos', values: [1,2,5,10,20,50] },
103+
],
104+
run: async ({ location_name, nPhotos }, printLog = console.log) => {
105+
const { items: locations } = await instagram.request({ method: 'search_location', params: [location_name] })
106+
107+
if (!locations.length) throw new Error(`Location ${location_name} not found`)
108+
109+
printLog(`Location search by '${location_name}': found ${locations.length} items.`)
110+
111+
const { location } = locations[0]
112+
113+
printLog(`Using '${location.name}'`)
114+
115+
const { items } = await instagram.request({ method: 'get_location_feed', params: [ location.pk ] })
116+
117+
printLog(`Loaded ${items.length} photos. Requested to like ${nPhotos}.`)
118+
119+
if (!items.length) {
120+
printLog(`Sorry, no photos to like in this location. Try more specific name.`)
121+
return
122+
}
123+
124+
return safeMap(items.slice(0, nPhotos), item => instagram.request({ method: 'like', params: [item.id] }), printLog)
125+
}
126+
},
127+
99128
load_followers: {
100129
name: 'Load full list of user followers',
101130
params: [

0 commit comments

Comments
 (0)