Skip to content

Commit 19b04a7

Browse files
committed
implement custom root path for multi accounts
closes #152
1 parent 0963f31 commit 19b04a7

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ I advise you to follow these guidelines:
5959
- Run the bot on the same internet connection (e.g. WiFi) as you normally use your phone with the Instagram mobile app. It will reduce the chance of being flagged
6060
- Use conservative parameters (max follows/unfollows per day 150 and max 20 per hour, maybe even start lower, and work your way up)
6161

62+
## Multiple accounts
63+
64+
To run the bot on multiple accounts at the same time, run it with the command line argument `--root` to specify a unique path for each instance:
65+
66+
```
67+
/path/to/SimpleInstaBot --root ~/Desktop/account1
68+
/path/to/SimpleInstaBot --root ~/Desktop/account2
69+
```
70+
6271
## API / programmatic bot
6372

6473
SimpleInstaBot is built on [instauto](https://github.com/mifi/instauto) - you can instead use that if you want to program your own headless bot.
@@ -89,8 +98,6 @@ DISPLAY=:0 ./simpleinstabot --no-sandbox
8998

9099
## FAQ
91100

92-
- Q: Can I run it on multiple accounts at the same time?
93-
- A: No, currently you would need multiple PC's or multiple VMs for that. See [#27](https://github.com/mifi/SimpleInstaBot/issues/27)
94101
- Q: Can I run it on multiple accounts (but not at the same time)?
95102
- A: Yes, just log out, and then log in to your other account instead. Followed/liked etc will be remembered.
96103

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"lodash": "^4.17.21",
2626
"moment": "^2.29.4",
2727
"puppeteer-core": "^15.4.0",
28-
"puppeteer-in-electron": "^3.0.5"
28+
"puppeteer-in-electron": "^3.0.5",
29+
"yargs-parser": "^21.0.1"
2930
},
3031
"scripts": {
3132
"start:frontend": "BROWSER=none PORT=3001 react-scripts start",

public/electron.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@ const { join } = require('path');
77
const assert = require('assert');
88
const fs = require('fs-extra');
99
const filenamify = require('filenamify');
10+
const yargsParser = require('yargs-parser');
1011

1112
const Instauto = require('instauto');
1213
const moment = require('moment');
1314
const electronRemote = require('@electron/remote/main'); // todo migrate away from this
1415

1516

16-
function getFilePath(rel) {
17-
return join(app.getPath('userData'), rel);
18-
}
19-
20-
const cookiesPath = getFilePath('cookies.json');
21-
2217
// Keep a global reference of the window object, if you don't, the window will
2318
// be closed automatically when the JavaScript object is garbage collected.
2419
let mainWindow;
@@ -41,6 +36,31 @@ pieConnectPromise.catch(console.error);
4136

4237
electronRemote.initialize();
4338

39+
function parseCliArgs() {
40+
const ignoreFirstArgs = isDev ? 2 : 1;
41+
// production: First arg is the app executable
42+
// dev: First 2 args are electron and the electron.js
43+
const argsWithoutAppName = process.argv.length > ignoreFirstArgs ? process.argv.slice(ignoreFirstArgs) : [];
44+
45+
return yargsParser(argsWithoutAppName);
46+
}
47+
48+
const args = parseCliArgs();
49+
console.log('CLI arguments', args);
50+
const { root: customRootPath } = args;
51+
52+
if (customRootPath) {
53+
console.log('Using custom root', customRootPath);
54+
// must happen before 'ready' event
55+
app.setPath('userData', join(customRootPath, 'electron'));
56+
}
57+
58+
function getFilePath(rel) {
59+
return join(customRootPath || app.getPath('userData'), rel);
60+
}
61+
62+
const cookiesPath = getFilePath('cookies.json');
63+
4464
async function checkHaveCookies() {
4565
return fs.pathExists(cookiesPath);
4666
}
@@ -251,7 +271,6 @@ async function runTestCode() {
251271
// console.log(await instauto.doesUserFollowMe('mifi.no'));
252272
}
253273

254-
255274
function createWindow() {
256275
// Create the browser window.
257276
mainWindow = new BrowserWindow({

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11249,7 +11249,7 @@ yargs-parser@^20.2.2:
1124911249
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee"
1125011250
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==
1125111251

11252-
yargs-parser@^21.0.0:
11252+
yargs-parser@^21.0.0, yargs-parser@^21.0.1:
1125311253
version "21.0.1"
1125411254
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35"
1125511255
integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==

0 commit comments

Comments
 (0)