Anurag Kumar
Published © MIT

Live Insta Following/Follower Counter

Now visualize Insta Following/Follower Counter using Arduino and Bolt and a live running python script.

IntermediateFull instructions provided4 hours3,008
Live Insta Following/Follower Counter

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Arduino UNO
Arduino UNO
×1
USB-A to B Cable
USB-A to B Cable
×1
Sunfounder 16×2 Liquid Crystal Display
×1
Texas Instruments I2C Serial Interface Adapter Module
×1
Male/Male Jumper Wires
×3
Male/Female Jumper Wires
Male/Female Jumper Wires
×4

Software apps and online services

Arduino IDE
Arduino IDE
Bolt Cloud
Bolt IoT Bolt Cloud
Snappy Ubuntu Core
Snappy Ubuntu Core

Story

Read more

Schematics

Arduino and LCD display

Arduino and Bolt Board

Code

Python Code

Python
import requests
import json
import time
from boltiot import Bolt

bolt_api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXX"  # Replace the string with the API key 
device_id = "BOLTXXXXXX"    # Replace the string with your Bolt ID
insta_username = "anurag_3301" # Replace it with your Instagram Username 

mybolt = Bolt(bolt_api_key, device_id)      # Connecting to the cloud using the API key and Bolt ID
response = mybolt.serialBegin('9600')       # Establishing UART Communication with 9600 baud rate
print(response)     # Printing the response for troubleshooting 

# This function takes the Insta Username as argument and returns a dictionary with following and follower count
def get_insta_count(username):
    url = 'https://www.instagram.com/' + username + "/?__a=1"   # creating the url for request
    r = requests.get(url)       # request for data for the username 
    data = json.loads(r.text)   # loading the data as JSON
    # now return in form of a dictionary 
    return {"followers":data["graphql"]["user"]["edge_followed_by"]["count"] , "following": data["graphql"]["user"]["edge_follow"]["count"]}

while True:
    data = get_insta_count(insta_username) # calling the get_insta_count function for data
    followers = str(data["followers"])  # extrating the followers count
    following = str(data["following"])  # extrating the following count
    send = followers + "$" + following  # creating a string with followers and following count seperated by '$'
    response = mybolt.serialWrite(send) # Sending the data to arduino though UART line
    print(response)     # response for troubleshooting
    time.sleep(60)      # updating every minute 

Arduino code

Arduino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2);

void setup(){
    lcd.begin();
    lcd.backlight();
    lcd.print("");
    Serial.begin(9600);
    Serial.setTimeout(50);
}

void loop(){
    String inString = "";
    String val[2] = {"", ""};
    if (Serial.available() > 0){
        lcd.clear();
        inString = Serial.readString();
        int index = 0;
        for (int i = 0; i < inString.length(); i++){
            if (inString[i] == '$'){
                index = 1;
                continue;
            }
            val[index] += inString[i];
        }
        lcd.setCursor(0, 0);
        lcd.print("Followers " + val[0]);
        lcd.setCursor(0, 1);
        lcd.print("Following " + val[1]);
    }
}

Credits

Anurag Kumar

Anurag Kumar

1 project • 1 follower

Comments