DEV Community

Shaffan
Shaffan

Posted on

A Simple Instagram Tracking Script Written in Python

proof of concept

python3 main.py -h
usage: Instagram Tracker [-h] -u USERNAME

📸 an Instagram tracker that logs any changes to an Instagram account
(followers, following, posts, and bio)

options:
  -h, --help            show this help message and exit
  -u USERNAME, --username USERNAME
                        The username of the account to track

🤝 Contribute: https://github.com/ibnaleem/instatracker
Enter fullscreen mode Exit fullscreen mode

You must login to your Instagram account in order to properly scrape someone else's Instagram account. This is due to Instagram blocking HTTPS GET requests from unauthenticated cookies. Your login information is never stored. See more here and here.

You can always create/use an alt-account for the login.

Installation

Install Python if you don't have it already

Clone this repository:

$ git clone https://github.com/ibnaleem/instatracker.git
Enter fullscreen mode Exit fullscreen mode

Install dependencies:

$ pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Set user & passwd field on line 56

self.bot.login(user="YOUR INSTAGRAM USERNAME", passwd="YOUR INSTAGRAM PASSWORD") # this allows us to access & scrape Instagram.
Enter fullscreen mode Exit fullscreen mode

Run the script

$ python3 main.py -u USERNAME
Enter fullscreen mode Exit fullscreen mode

Automated Logging

InstaTracker not only displays all modifications an Instagram account makes directly to the terminal (e.g., USERNAME has unfollowed 1 person), but it also records these changes in a text file, including the date and time.

------2024-06-30 01:01:13.659694+00:00------
johndoe has 100
johndoe is following 100 people
johndoe has 0 posts
johndoe has the following bio: this is my biography
------2024-06-31 02:03:15.761715+00:00------
johndoe has lost 2 followers (100 followers --> 98 followers)
------2024-06-31 05:03:15.761715+00:00------
johndoe has gained 5 followers (98 followers --> 103 followers)
...
Enter fullscreen mode Exit fullscreen mode

This script checks for any changes every 5 minutes because Instagram's firewall starts blocking requests that are sent too quickly. You can manually update this here, but do not be surprised if the script stops working.

Built With

LICENSE

This repository is under the MIT License

Created By

Ibn Aleem

Top comments (0)