What's an Instagram bot? Basically, you feed the bot your Instagram user/password, and it executes follows/unfollows/likes/comments on your behalf based on rules you set. (I set my bot to like one photo tagged with "#penguin" per-run)
Great power, right? A client (yes, you can hire me!) asked me to integrate InstaPy into their swarm, and this recipe is the result.
Setup data locations¶
We need a data location to store InstaPy's config, as well as its log files. Create /var/data/instapy per below
mkdir -p /var/data/instapy/logs
Setup Docker Swarm¶
Create a docker swarm config file in docker-compose syntax (v3), something like this:
I share (with my patreon patrons) a private "premix" git repository, which includes necessary docker-compose and env files for all published recipes. This means that patrons can launch any recipe with just a
git pull and a
docker stack deploy 👍
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
version: '3' services: web: command: ["./wait-for", "selenium:4444", "--", "python", "docker_quickstart.py"] environment: - PYTHONUNBUFFERED=0 # Modify the image to whatever Tim's image tag ends up as. I used funkypenguin/instapy for my build image: funkypenguin/instapy:latest # When using swarm, you can't use relative paths, so the following needs to be set to the full filesystem path to your logs and docker_quickstart.py # Bind-mount docker_quickstart.py, since now that we're using a public image, we can't "bake" our credentials into the image anymore volumes: - /var/data/instapy/logs:/code/logs - var/data/instapy/instapy.py:/code/docker_quickstart.py:ro # This section allows docker to restart the container when it exits (either normally or abnormally), which ensures that # InstaPy keeps re-running. Tweak the delay to avoid being banned for excessive activity deploy: restart_policy: condition: any delay: 3600s selenium: image: selenium/standalone-chrome-debug ports: - "5900:5900"
Setup unique static subnets for every stack you deploy. This avoids IP/gateway conflicts which can otherwise occur when you're creating/removing stacks a lot. See my list here.
Command your bot¶
Create a variation of https://github.com/timgrossmann/InstaPy/blob/master/docker_quickstart.py at /var/data/instapy/instapy.py (the file we bind-mounted in the swarm config above)
Change at least the following:
insta_username = '' insta_password = ''
Here's an example of my config, set to like a single penguin-pic per run:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
insta_username = 'funkypenguin' insta_password = 'followmemypersonalbrandisawesome' dont_like = ['food','girl','batman','gotham','dead','nsfw','porn','slut','baby','tv','athlete','nhl','hockey','estate','music','band','clothes'] friend_list = ['therock','ruinporn'] # If you want to enter your Instagram Credentials directly just enter # username=<your-username-here> and password=<your-password> into InstaPy # e.g like so InstaPy(username="instagram", password="test1234") bot = InstaPy(username='insta_username', password='insta_password', selenium_local_session=False) bot.set_selenium_remote_session(selenium_url='http://selenium:4444/wd/hub') bot.login() bot.set_upper_follower_count(limit=10000) bot.set_lower_follower_count(limit=10) bot.set_comments([u'Cool :penguin:!', u'Awesome :penguin:!!', u'Nice :penguin:!!']) bot.set_dont_include(friend_list) bot.set_dont_like(dont_like) #bot.set_ignore_if_contains(ignore_words) # OK, so go through my feed and like stuff, interacting with people I follow # bot.like_by_feed(amount=3, randomize=True, unfollow=True, interact=True) # Now find posts tagged as #penguin, and like 'em, commenting 50% of the time bot.set_do_comment(True, percentage=50) bot.set_comments([u'Cool :penguin:!', u'Awesome :penguin:!!', u'Nice :penguin:!!']) bot.like_by_tags(['#penguin'], amount=1) # goodnight, sweet bot bot.end()
Destroy all humans¶
Launch the bot by running
docker stack deploy instapy -c <path -to-docker-compose.yml>
While you're waiting for Docker to pull down the images, educate yourself on the risk of a robotic uprising:
After swarm deploys, you won't see much, but you can monitor what InstaPy is doing, by running
docker service logs instapy_web.
You can also watch the bot at work by VNCing to your docker swarm, password "secret". You'll see Selenium browser window cycling away, interacting with all your real/fake friends on Instagram :)
Chef's Notes 📓¶
- Amazingly, my bot has ended up tagging more non-penguins than actual penguins. I don't understand how Instagrammers come up with their hashtags!
Tip your waiter (support me) 👏¶
Did you receive excellent service? Want to make your waiter happy? (..and support development of current and future recipes!) See the support page for (free or paid) ways to say thank you! 👏
Flirt with waiter (subscribe) 💌¶
Want to know now when this recipe gets updated, or when future recipes are added? Subscribe to the RSS feed, or leave your email address below, and we'll keep you updated. (double-opt-in, no monkey business, no spam either - check the archive for proof!)