Skip to content

Instantly share code, notes, and snippets.

@YannickSF
Created January 16, 2023 23:23
Show Gist options
  • Save YannickSF/d9c7c5ac63d58bde994c1d2b01807aed to your computer and use it in GitHub Desktop.
Save YannickSF/d9c7c5ac63d58bde994c1d2b01807aed to your computer and use it in GitHub Desktop.

Quick Start :

Install dependances :

pip3 install -r requirements.txt

before launching script :

open script in editor there multiples variables in the top of the script.

  • ARGS, determine if the script launch by input parameters or with the assign one in the script.
  • ACCOUNT_USERNAME, "login" make sure to put the login between double quotes.
  • ACCOUNT_PASSWORD, "password" make sure to put the login between double quotes.
  • BOT_SLEEP, sleep time of success and bot's pause before restarting operation.

Start the script :

python3 stories_watcher.py <"login"> <"password"> <bot_sleep>

to stop program : ctrl + x

import sys
import time
from instagrapi import Client
class _Settings:
ARGS = True
ACCOUNT_USERNAME = ''
ACCOUNT_PASSWORD = ''
BOT_SLEEP = 10
SETTINGS = _Settings()
if __name__ == '__main__':
if SETTINGS.ARGS:
args = sys.argv
args.remove(sys.argv[0])
if len(args) < 2:
raise Exception('Invalid arguments')
ACCOUNT_USERNAME = args[0]
ACCOUNT_PASSWORD = args[1]
BOT_SLEEP = args[2] if len(args) >= 3 else SETTINGS.BOT_SLEEP
try:
print('Starting...')
cl = Client()
print('Try to connect.')
cl.login(SETTINGS.ACCOUNT_USERNAME, SETTINGS.ACCOUNT_PASSWORD)
print('Success.')
while True:
# insert task here
print('Bot pause : {0}.'.format(SETTINGS.BOT_SLEEP))
time.sleep(SETTINGS.BOT_SLEEP)
except Exception as ex:
print('Error of connect.')
print(ex.args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment