-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (45 loc) · 1.73 KB
/
main.py
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
import instaloader
import re
import os
def get_instagram_info(username):
loader = instaloader.Instaloader()
try:
profile = instaloader.Profile.from_username(loader.context, username)
loader.download_profilepic(profile)
user_info = {
"Name": profile.full_name,
"Username": profile.username,
"Followers": profile.followers,
"Following": profile.followees,
"Posts": profile.mediacount,
"Is Private": profile.is_private,
"Bio": profile.biography
}
return user_info
except instaloader.exceptions.ProfileNotExistsException:
return None
def save_user_info(username, user_info):
dir_name = username
if not os.path.exists(dir_name):
os.makedirs(dir_name)
info_file_path = os.path.join(dir_name, f"{username}.txt")
with open(info_file_path, "w", encoding="utf-8") as file:
for key, value in user_info.items():
if key != "Bio":
file.write(f"{key}: {value}\n")
bio_file_path = os.path.join(dir_name, f"bio{username}.txt")
with open(bio_file_path, "w", encoding="utf-8") as bio_file:
bio_file.write(user_info["Bio"])
def main():
input_username = input("Enter the Instagram username (with or without '@'): ")
username = re.sub(r'^@', '', input_username)
user_info = get_instagram_info(username)
if user_info:
save_user_info(username, user_info)
print(f"User information saved in {username}/{username}.txt")
print(f"User bio saved in {username}/bio{username}.txt")
print(f"Profile picture saved as {username}/{username}.png")
else:
print("User not found.")
if __name__ == "__main__":
main()