Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions instaLooter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
--traceback Print error traceback if any (debug).
-W WARNINGCTL Change warning behaviour (same as python -W).
[default: default]
--try-count NUM, -c NUM Do the login process NUM times
[default: 3]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be moved to the Options - Credentials section !


Template:
The default filename of the pictures and videos on Instagram doesn't show
Expand Down Expand Up @@ -161,15 +163,19 @@ def main(argv=None):
return 0

elif args['login']:
try:
args['--username'] = six.moves.input('Username: ')
login(InstaLooter(), args)
return 0
except ValueError as ve:
console.error(ve)
if args["--traceback"]:
traceback.print_exc()
return 1
for i in range(int(args['--try-count'])):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block can be rewritten this way (with less tests / local variables):

        args['--try-count'] = int(args['--try-count'])
        while args['--try-count']:
            try:
                args['--username'] = six.moves.input('Username: ')
                login(InstaLooter(), args)
                return 0
            except ValueError as ve:
                args['--try-count'] -= 1
                console.warn('Wrong Username or Password')
                if args["--traceback"]:
                    traceback.print_exc()
        return 1

try:
args['--username'] = six.moves.input('Username: ')
login(InstaLooter(), args)
return 0
except ValueError as ve:
if i != int(args['--try-count']) - 1:
console.warn('Wrong Username or Password')
continue
console.error(str(ve) + ', the number of tries exceeded')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just show the message here, the ValueError text is not needed since it can be displayed with --traceback if needed.

if args["--traceback"]:
traceback.print_exc()
return 1

if args['-W'] not in WARNING_ACTIONS:
print("Unknown warning action: {}".format(args['-W']))
Expand Down Expand Up @@ -204,17 +210,36 @@ def main(argv=None):
extended_dump=args['--extended-dump'],
)

try:
login(looter, args)
if args['--time']:
timeframe = get_times_from_cli(args['--time'])
else:
timeframe = None
except ValueError as ve:
console.error(ve)
if args["--traceback"]:
traceback.print_exc()
return 1
userEntered = False
passEntered = False
if args['--username'] != None:
userEntered = True
if args['--password'] != None:
passEntered = True
if userEntered and passEntered:
args['--try-count'] = 1

for i in range(int(args['--try-count'])):
try:
if not userEntered:
args['--username'] = six.moves.input('Username: ')
login(looter, args)
if args['--time']:
timeframe = get_times_from_cli(args['--time'])
else:
timeframe = None
except ValueError as ve:
if i != int(args['--try-count']) - 1:
console.warn('Wrong Username or Password')
continue

if userEntered and passEntered:
console.error(str(ve))
else:
console.error(str(ve) + ', the number of tries exceeded')
if args["--traceback"]:
traceback.print_exc()
return 1

try:
post_token = args['<post_token>']
Expand Down