-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsta_test_2.py
More file actions
66 lines (49 loc) · 1.53 KB
/
Copy pathinsta_test_2.py
File metadata and controls
66 lines (49 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import logging
from typing import List, Dict, Any
from apify_client import ApifyClient
from apify_client._errors import ApifyApiError
def fetch_profiles_insta(
usernames: List[str],
include_about: bool = False,
timeout_secs: int = 30
) -> List[Dict[str, Any]]:
"""
Runs Apify Instagram profile searcher and returns parsed results.
"""
# print(os.getenv("APIFY_API"))
client = ApifyClient(os.getenv("APIFY_API"))
INSTA_ACTOR_ID = "apify/instagram-profile-scraper"
run_input = {
"includeAboutSection": include_about,
"usernames": usernames,
}
try:
run = client.actor(INSTA_ACTOR_ID).call(
run_input=run_input,
timeout_secs=timeout_secs
)
dataset_id = run["defaultDatasetId"]
results = list(
client.dataset(dataset_id).iterate_items()
)
return results
except ApifyApiError as e:
return f"Apify API error: {e}"
except Exception as e:
return "Unexpected error while fetchinjg profiles"
logger = logging.getLogger(__name__)
def get_profiles(usernames: list[str]):
try:
results = fetch_profiles_insta(usernames)
return {"success": True, "data": results}
except Exception:
return ("Instagram lookup failed")
d = get_profiles(["hanavmodasiya"])
# print(d)
if (d["success"] == False):
print("Username doesnt exist")
else:
print(d["data"][0]["username"])
print(d["data"][0]["fullName"])
print(d["data"][0]["profilePicUrlHD"])