Repository: InstaPy/InstaPy

Issue:
ValueError: empty range for randrange() (0,0, 0)
<!-- Is this a Feature Request ? Please, check out our Wiki first https://github.com/timgrossmann/InstaPy/wiki -->
## Expected Behavior
running session.interact_user_followers([a], amount=10, randomize=True) where [a] = [my own username]

I expect it to interact with my users if i put my own username 
## Current Behavior

It's crashing with the below error after gathering data and returning an empty list for some reason
ValueError: empty range for randrange() (0,0, 0)

## Possible Solution (optional)
## InstaPy configuration




Discussion:
Yes @halalfood 
It happens in the rarest scenarios of where the simulated follows count equals to the desired amount set by user.
```python
person_list = person_list[:(real_amount-len(simulated_list))]
```
at that scenario, `person_list` will get an empty list.

After that, in line
```python
person_list.insert(random.randint(0, len(person_list)-1), user)
```
it will try to generate a random numerical value from `(0, -1)` range which will opt out the problem you have encountered.
```powershell
ValueError: empty range for randrange() (0,0, 0)
```


**To solve**,
**replace**
```python
person_list.insert(random.randint(0, len(person_list)-1), user)
```
**with**
```python
person_list.insert(random.randint(0, abs(len(person_list)-1)), user)
```
_added `abs` to always return the absolute value in case of that rare `-1` situation_.

>It could be great if you did include a good console output of the error. Cos it took some time to realize how it has happened.

Also, all of the modifications and references belong to `get_users_through_dialog` definition in **unfollow_util.py** file.

Cheer
Thank you for your detailed response @uluQulu .

I tested it and still get the following error: 

```
Traceback (most recent call last):
  File "/Users/piratze/Documents/GitHub/InstaPy/quickstart.py", line 73, in <module>
    session.interact_user_following([a], amount=10, randomize=True)
  File "/Users/piratze/Documents/GitHub/InstaPy/instapy/instapy.py", line 1834, in interact_user_following
    self.logfolder)
  File "/Users/piratze/Documents/GitHub/InstaPy/instapy/unfollow_util.py", line 825, in get_given_user_following
    logger, logfolder)
  File "/Users/piratze/Documents/GitHub/InstaPy/instapy/unfollow_util.py", line 590, in get_users_through_dialog
    quick_index = random.randint(0, len(follow_buttons)-1)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/random.py", line 221, in randint
    return self.randrange(a, b+1)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/random.py", line 199, in randrange
    raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0,0, 0)

Process finished with exit code 1
```
@halalfood 
Patch it too!
You were having another bug than I realized but it is the same situation.

in `get_users_through_dialog` definition of **unfollow_util.py** file
**replace**
```python
        if (simulator_counter > random.randint(5, 17) or
                abort==True or
                    total_list >= amount or
                        sc_rolled==random.randint(3, 5)):
```
**with**
```python
        if ((simulator_counter > random.randint(5, 17) or
                abort==True or
                    total_list >= amount or
                        sc_rolled==random.randint(3, 5)) and
                            len(follow_buttons) > 0):
```
_Let me know if it works._

I still wonder how it cannot find any buttons, maybe you do see "Follow Back" instead of "Follow", eh?
so far doing both those changes allows interact_user_following to work. I don't see "follow back", at least not with that function. I think if you want to make a PR, please do so to fix it for others as well! appreciate your help @uluQulu 
Glad to help, @halalfood
It would be better if you could PR cos I have a busy git traffic with other major implementation to be shared soon.

Resolving patch:
diff --git a/instapy/unfollow_util.py b/instapy/unfollow_util.py
--- a/instapy/unfollow_util.py
+++ b/instapy/unfollow_util.py
@@ -577,10 +577,11 @@ def get_users_through_dialog(browser,
                 sc_rolled = 0
 
         # Will follow a little bit of users in order to simulate real interaction
-        if (simulator_counter > random.randint(5, 17) or
+        if ((simulator_counter > random.randint(5, 17) or
                 abort==True or
                     total_list >= amount or
-                        sc_rolled==random.randint(3, 5)):
+                        sc_rolled==random.randint(3, 5)) and
+	    			len(follow_buttons) > 0):
 
             quick_amount = 1 if not total_list >= amount else random.randint(1, 4)
 
@@ -613,7 +614,7 @@ def get_users_through_dialog(browser,
     person_list = person_list[:(real_amount-len(simulated_list))]
     for user in simulated_list:   #add simulated users to the `person_list` in random index
         if user not in person_list:
-            person_list.insert(random.randint(0, len(person_list)-1), user)
+            person_list.insert(random.randint(0, abs(len(person_list)-1)), user)
 
     return person_list, simulated_list
 


Test patch: