-
Notifications
You must be signed in to change notification settings - Fork 4
/
instadp.py
executable file
·71 lines (58 loc) · 1.61 KB
/
instadp.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
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
import webbrowser
import requests
from instagramy import InstagramUser
"""
Usage: python instagram_dp.py <username>
package_used: https://github.com/yogeshwaran01/instagramy
visit is page to get more usage about package
Author: YOGESHWARAN R
"""
def get_dp(username: str) -> str:
"""
Funtion to get dp url of the username
"""
try:
user = InstagramUser(username)
return user.profile_picture_url
except (KeyError, TypeError, IndexError):
print("username not found")
sys.exit(1)
def download(username: str) -> None:
"""
Funtion to download the dp
"""
dp_url = get_dp(username)
file_name = "{}.jpeg".format(username)
r = requests.get(dp_url, stream=True)
if r.ok:
file = open(file_name, "wb")
file.write(r.content)
print("{}'s dp downloaded!".format(username))
else:
print("Check your internet connection")
def opener(username: str) -> None:
"""
Funtion to open dp in default webbrowser
"""
url = get_dp(username)
print("{}'s dp is opening...".format(username))
webbrowser.open(url)
if __name__ == "__main__":
try:
username = sys.argv[1]
except IndexError:
username = str(input("Enter the Username: "))
prompt = """
[1] Download
[2] Open
"""
print(prompt)
option = str(input(">>> "))
if option == "1":
download(username)
elif option == "2":
opener(username)
else:
print("press 1 or 2")
sys.exit()