Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,76 +7,62 @@ import os
|
|
7 |
API_KEY = os.getenv("INSTA_API")
|
8 |
|
9 |
# API Details
|
10 |
-
API_URL = "https://
|
11 |
HEADERS = {
|
12 |
"x-rapidapi-key": API_KEY,
|
13 |
-
"x-rapidapi-host": "
|
14 |
}
|
15 |
|
16 |
# Streamlit UI
|
17 |
-
st.set_page_config(page_title="Instagram
|
18 |
-
st.title("πΈ Instagram
|
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={"
|
30 |
-
|
31 |
if response.status_code == 200:
|
32 |
data = response.json()
|
33 |
st.success("β
Data Retrieved Successfully!")
|
34 |
|
35 |
-
#
|
36 |
-
st.subheader("
|
37 |
-
|
38 |
-
if "full_name" in data:
|
39 |
-
st.write(f"**Full Name:** {data['full_name']}")
|
40 |
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
#
|
54 |
-
profile_pic = data.get("
|
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 |
|