-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (71 loc) · 2.77 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import terminal
import instaloader
import instaloaderManager
import sessionManager
username = None
# Defining the available actions
actions = {
'1': '1. Download Posts',
'2': '2. Download Stories',
'3': '3. Download Highlights'
}
# Showing the boot logo
terminal.boot()
# Making sure the platform is windows
if not os.name == 'nt':
terminal.error('This script is currently only available on Windows.', shouldExit=True)
sessions = sessionManager.get_sessions()
# Checking if there are any sessions available
if len(sessions) == 0:
terminal.info('There are no sessions available. Would you like to run the cookie_script.py? [y/n]')
answer = input()
while answer.lower() not in ['y', 'n', 'yes', 'no']:
terminal.error('Invalid answer. Accepted answers: y, n, yes, no.')
answer = input()
if answer in ['y', 'yes']:
exec(open('./cookie_script.py', 'r').read())
exit(1)
terminal.info('Which account do you want to use?')
terminal.info(f'Available accounts: ' + ', '.join(sessions))
username = input()
while username not in sessions:
terminal.error(f'Invalid account. Available accounts: ' + ', '.join(sessions))
username = input()
terminal.info(f'Attempting to login to Instagram as {username}.')
# Trying to sign in to Instagram
L = instaloader.Instaloader(quiet=True)
try:
L.load_session_from_file(username=username)
except instaloader.exceptions.BadCredentialsException:
terminal.error(f'The password is not valid.', shouldExit=True)
except instaloader.exceptions.ConnectionException as ConnectionException:
terminal.error(ConnectionException, shouldExit=True)
terminal.success(f'Logged in as {username}.')
terminal.info('Enter the profile name you want to interact with: ')
profile = input()
# Validating profile
try:
profile = instaloader.Profile.from_username(L.context, profile)
except instaloader.exceptions.ProfileNotExistsException:
terminal.error(f'The profile {profile} does not exist.', shouldExit=True)
# Checking if the profile can be interacted with
if profile.is_private and not profile.followed_by_viewer:
terminal.error(f'{profile.username} is private and you are not following them.', shouldExit=True)
# Showing available options
terminal.info(f'What action do you want to perform on {profile.username}?')
for action in actions.values():
terminal.info(action, prefix=False)
action = input()
while action not in actions:
terminal.error('Invalid action. Available actions:')
for action in actions.values():
terminal.info(action, prefix=False)
action = input()
match action:
case '1':
instaloaderManager.download_posts(L, profile)
case '2':
instaloaderManager.download_stories(L, profile)
case '3':
instaloaderManager.download_highlights(L, profile)