instauto 8.0.1 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +19 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -210,6 +210,10 @@ const Instauto = async (db, browser, options) => {
|
|
|
210
210
|
return safeGotoUser(url, username);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
async function navigateToUserWithCheck(username) {
|
|
214
|
+
if (!(await navigateToUser(username))) throw new Error('User not found');
|
|
215
|
+
}
|
|
216
|
+
|
|
213
217
|
async function getPageJson() {
|
|
214
218
|
return JSON.parse(await (await (await page.$('pre')).getProperty('textContent')).jsonValue());
|
|
215
219
|
}
|
|
@@ -226,11 +230,11 @@ const Instauto = async (db, browser, options) => {
|
|
|
226
230
|
|
|
227
231
|
const { user } = json.graphql;
|
|
228
232
|
|
|
229
|
-
await
|
|
233
|
+
await navigateToUserWithCheck(username);
|
|
230
234
|
return user;
|
|
231
235
|
}
|
|
232
236
|
|
|
233
|
-
await
|
|
237
|
+
await navigateToUserWithCheck(username);
|
|
234
238
|
|
|
235
239
|
// eslint-disable-next-line no-underscore-dangle
|
|
236
240
|
const sharedData = await page.evaluate(() => window._sharedData);
|
|
@@ -311,8 +315,8 @@ const Instauto = async (db, browser, options) => {
|
|
|
311
315
|
return elementHandles[0];
|
|
312
316
|
}
|
|
313
317
|
|
|
314
|
-
|
|
315
|
-
|
|
318
|
+
async function followUser(username) {
|
|
319
|
+
await navigateToUserWithCheck(username);
|
|
316
320
|
const elementHandle = await findFollowButton();
|
|
317
321
|
|
|
318
322
|
if (!elementHandle) {
|
|
@@ -353,7 +357,8 @@ const Instauto = async (db, browser, options) => {
|
|
|
353
357
|
|
|
354
358
|
// See https://github.com/timgrossmann/InstaPy/pull/2345
|
|
355
359
|
// https://github.com/timgrossmann/InstaPy/issues/2355
|
|
356
|
-
async function
|
|
360
|
+
async function unfollowUser(username) {
|
|
361
|
+
await navigateToUserWithCheck(username);
|
|
357
362
|
logger.log(`Unfollowing user ${username}`);
|
|
358
363
|
|
|
359
364
|
const res = { username, time: new Date().getTime() };
|
|
@@ -549,9 +554,11 @@ const Instauto = async (db, browser, options) => {
|
|
|
549
554
|
/* eslint-enable no-undef */
|
|
550
555
|
|
|
551
556
|
|
|
552
|
-
async function
|
|
557
|
+
async function likeUserImages({ username, likeImagesMin, likeImagesMax } = {}) {
|
|
553
558
|
if (!likeImagesMin || !likeImagesMax || likeImagesMax < likeImagesMin || likeImagesMin < 1) throw new Error('Invalid arguments');
|
|
554
559
|
|
|
560
|
+
await navigateToUserWithCheck(username);
|
|
561
|
+
|
|
555
562
|
logger.log(`Liking ${likeImagesMin}-${likeImagesMax} user images`);
|
|
556
563
|
try {
|
|
557
564
|
await page.exposeFunction('instautoSleep', sleep);
|
|
@@ -613,14 +620,14 @@ const Instauto = async (db, browser, options) => {
|
|
|
613
620
|
) {
|
|
614
621
|
logger.log('User has too many followers compared to follows or opposite, skipping');
|
|
615
622
|
} else {
|
|
616
|
-
await
|
|
623
|
+
await followUser(follower);
|
|
617
624
|
numFollowedForThisUser += 1;
|
|
618
625
|
|
|
619
626
|
await sleep(10000);
|
|
620
627
|
|
|
621
628
|
if (!isPrivate && enableLikeImages && !hasReachedDailyLikesLimit()) {
|
|
622
629
|
try {
|
|
623
|
-
await
|
|
630
|
+
await likeUserImages({ username: follower, likeImagesMin, likeImagesMax });
|
|
624
631
|
} catch (err) {
|
|
625
632
|
logger.error(`Failed to follow user's images ${follower}`, err);
|
|
626
633
|
await takeScreenshot();
|
|
@@ -684,7 +691,7 @@ const Instauto = async (db, browser, options) => {
|
|
|
684
691
|
await addPrevUnfollowedUser({ username, time: new Date().getTime(), noActionTaken: true });
|
|
685
692
|
await sleep(3000);
|
|
686
693
|
} else {
|
|
687
|
-
const { noActionTaken } = await
|
|
694
|
+
const { noActionTaken } = await unfollowUser(username);
|
|
688
695
|
|
|
689
696
|
if (noActionTaken) {
|
|
690
697
|
await sleep(3000);
|
|
@@ -901,15 +908,12 @@ const Instauto = async (db, browser, options) => {
|
|
|
901
908
|
|
|
902
909
|
// --- END OF INITIALIZATION
|
|
903
910
|
|
|
904
|
-
|
|
905
911
|
async function doesUserFollowMe(username) {
|
|
906
912
|
try {
|
|
907
913
|
logger.info('Checking if user', username, 'follows us');
|
|
908
914
|
const userData = await navigateToUserAndGetData(username);
|
|
909
915
|
const userId = userData.id;
|
|
910
916
|
|
|
911
|
-
if (!(await navigateToUser(username))) throw new Error('User not found');
|
|
912
|
-
|
|
913
917
|
const elementHandles = await page.$x("//a[contains(.,' following')][contains(@href,'/following')]");
|
|
914
918
|
if (elementHandles.length === 0) throw new Error('Following button not found');
|
|
915
919
|
|
|
@@ -1011,8 +1015,9 @@ const Instauto = async (db, browser, options) => {
|
|
|
1011
1015
|
unfollowNonMutualFollowers,
|
|
1012
1016
|
unfollowAllUnknown,
|
|
1013
1017
|
unfollowOldFollowed,
|
|
1014
|
-
|
|
1015
|
-
|
|
1018
|
+
followUser,
|
|
1019
|
+
unfollowUser,
|
|
1020
|
+
likeUserImages,
|
|
1016
1021
|
sleep,
|
|
1017
1022
|
listManuallyFollowedUsers,
|
|
1018
1023
|
getFollowersOrFollowing,
|