instascrapperrr / app.py
7jimmy's picture
Update app.py
891b86c verified
import streamlit as st
import json
from profile_data import Instagram
import instaloader
from instaloader import Profile, Post
from itertools import islice
from math import ceil
import humanize
from tqdm import tqdm
def login_with_progress(INSTAGRAM_USERNAME, INSTAGRAM_PASSWORD):
# Get instance
instance = instaloader.Instaloader()
# Optionally, login session
with tqdm(total=1, desc='Logging in', unit='step') as pbar:
try:
instance.login(INSTAGRAM_USERNAME, INSTAGRAM_PASSWORD) # (login)
pbar.update(1)
pbar.set_postfix(status='Logged in')
return instance
except Exception as e:
pbar.set_postfix(status='Error')
st.error(f"Error: {e}")
return None
# Get Profile Info
def get_profile_info(username, instance):
profile_scrap = Instagram.scrap(username=username) # Call Scrap method from Instagram File
data_dict = json.loads(profile_scrap)
edge_followed_by_value = data_dict.get("edge_followed_by", 0)
edge_follow = data_dict.get("edge_follow", 0)
posts = data_dict.get("edge_owner_to_timeline_media", [])
insta_posts = posts['count']
insta_followers = humanize.intword(edge_followed_by_value['count'])
insta_following = edge_follow['count']
st.subheader("Profile Information")
st.write(f"**Posts:** {insta_posts}")
st.write(f"**Followers:** {insta_followers}")
st.write(f"**Following:** {insta_following}")
# Streamlit App
def main():
st.title("Instagram Profile Analyzer")
INSTAGRAM_USERNAME = st.text_input("Enter your Instagram username:")
INSTAGRAM_PASSWORD = st.text_input("Enter your Instagram password:", type="password")
if st.button("Login"):
instance = login_with_progress(INSTAGRAM_USERNAME, INSTAGRAM_PASSWORD)
if instance:
st.success("Login successful!")
st.sidebar.subheader("Choose an action:")
selected_action = st.sidebar.radio(
"Select an action",
["Profile Information", "Get Profile Highlights", "Instagram Stories",
"Saved Collection", "Full Account", "Post Likes and Ghost Users", "Most Like Picture"]
)
if selected_action == "Profile Information":
username = st.text_input("Enter the Instagram username:")
get_profile_info(username, instance)
# Add other actions here...
else:
st.error("Login failed. Please try again.")
if __name__ == "__main__":
main()