gskdsrikrishna commited on
Commit
d89d5ff
Β·
verified Β·
1 Parent(s): d61a13c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -45
app.py CHANGED
@@ -7,76 +7,62 @@ import os
7
  API_KEY = os.getenv("INSTA_API")
8
 
9
  # API Details
10
- API_URL = "https://instagram230.p.rapidapi.com/user/details"
11
  HEADERS = {
12
  "x-rapidapi-key": API_KEY,
13
- "x-rapidapi-host": "instagram230.p.rapidapi.com"
14
  }
15
 
16
  # Streamlit UI
17
- st.set_page_config(page_title="Instagram User Details", layout="wide")
18
- st.title("πŸ“Έ Instagram User Details")
19
-
20
- # Sidebar for options
21
- st.sidebar.header("Options")
22
- show_json = st.sidebar.checkbox("Show Raw JSON Response", value=False)
23
 
24
  # User Input
25
  username = st.text_input("Enter Instagram Username:", "mrbeast")
26
 
27
  if st.button("Fetch Details"):
28
  with st.spinner("Fetching data..."):
29
- response = requests.get(API_URL, headers=HEADERS, params={"username": username})
30
-
31
  if response.status_code == 200:
32
  data = response.json()
33
  st.success("βœ… Data Retrieved Successfully!")
34
 
35
- # Extracting and Displaying Structured Information
36
- st.subheader("πŸ“„ User Profile Details")
37
-
38
- if "full_name" in data:
39
- st.write(f"**Full Name:** {data['full_name']}")
40
 
41
- if "username" in data:
42
- st.write(f"**Username:** @{data['username']}")
43
 
44
- if "biography" in data and data["biography"]:
45
- st.write(f"**Bio:** {data['biography']}")
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- if "follower_count" in data:
48
- st.write(f"**Followers:** {data['follower_count']}")
49
 
50
- if "following_count" in data:
51
- st.write(f"**Following:** {data['following_count']}")
52
 
53
- # Display Profile Picture
54
- profile_pic = data.get("profile_pic_url_hd") or data.get("profile_pic_url")
55
  if profile_pic:
56
  st.image(profile_pic, caption="Profile Picture")
57
  img_bytes = requests.get(profile_pic).content
58
  st.download_button(label="Download Profile Picture", data=img_bytes, file_name=f"{username}_profile.jpg", mime="image/jpeg")
59
 
60
- # Extracting and Displaying Links
61
- links = []
62
- if "external_url" in data and data["external_url"]:
63
- links.append(data["external_url"])
64
-
65
- if "bio_links" in data and isinstance(data["bio_links"], list):
66
- links.extend([link["url"] for link in data["bio_links"] if "url" in link and link["url"]])
67
-
68
- if links:
69
- st.subheader("πŸ”— Relevant Links:")
70
- for link in links:
71
- st.markdown(f"[πŸ”— {link}]({link})")
72
- else:
73
- st.info("No links found in the profile.")
74
-
75
- # Option to Show Raw JSON Data
76
- if show_json:
77
- st.subheader("πŸ“œ Raw JSON Data")
78
- st.json(data)
79
-
80
  else:
81
  st.error("❌ Failed to retrieve data. Please check the username.")
82
 
 
7
  API_KEY = os.getenv("INSTA_API")
8
 
9
  # API Details
10
+ API_URL = "https://instagram-scraper-api2.p.rapidapi.com/v1/info"
11
  HEADERS = {
12
  "x-rapidapi-key": API_KEY,
13
+ "x-rapidapi-host": "instagram-scraper-api2.p.rapidapi.com"
14
  }
15
 
16
  # Streamlit UI
17
+ st.set_page_config(page_title="Instagram Scraper", layout="wide")
18
+ st.title("πŸ“Έ Instagram Scraper API")
 
 
 
 
19
 
20
  # User Input
21
  username = st.text_input("Enter Instagram Username:", "mrbeast")
22
 
23
  if st.button("Fetch Details"):
24
  with st.spinner("Fetching data..."):
25
+ response = requests.get(API_URL, headers=HEADERS, params={"username_or_id_or_url": username})
26
+
27
  if response.status_code == 200:
28
  data = response.json()
29
  st.success("βœ… Data Retrieved Successfully!")
30
 
31
+ # **Display JSON Response by Default**
32
+ st.subheader("πŸ“œ JSON Response")
33
+ st.json(data)
 
 
34
 
35
+ # Extracting Links
36
+ links = [value for key, value in data.items() if isinstance(value, str) and value.startswith("http")]
37
 
38
+ # Display Links Below JSON
39
+ if links:
40
+ st.subheader("πŸ”— Extracted Links:")
41
+ for link in links:
42
+ st.markdown(f"[πŸ”— {link}]({link})")
43
+ else:
44
+ st.info("No links found in the response.")
45
+
46
+ # **Download Buttons Below Links**
47
+ st.subheader("⬇️ Download Data")
48
+
49
+ # Convert JSON to formatted text
50
+ json_data = json.dumps(data, indent=4)
51
+ text_data = "\n".join(f"{key}: {value}" for key, value in data.items())
52
 
53
+ # Download JSON File
54
+ st.download_button(label="Download JSON", data=json_data, file_name=f"{username}_data.json", mime="application/json")
55
 
56
+ # Download Text File
57
+ st.download_button(label="Download Text", data=text_data, file_name=f"{username}_details.txt", mime="text/plain")
58
 
59
+ # Download Profile Picture (If available)
60
+ profile_pic = data.get("profile_picture")
61
  if profile_pic:
62
  st.image(profile_pic, caption="Profile Picture")
63
  img_bytes = requests.get(profile_pic).content
64
  st.download_button(label="Download Profile Picture", data=img_bytes, file_name=f"{username}_profile.jpg", mime="image/jpeg")
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  else:
67
  st.error("❌ Failed to retrieve data. Please check the username.")
68