We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Unfollow end prematurelly 
Hello I made the following script, but after it unfollows 19 people it neatly ends the session.
Why is it ending prematurly? 

from instapy import InstaPy
import os
session = InstaPy(username='login', password='pass')
session.login()
session.set_do_follow(enabled=True, percentage=97, times=1)
##session.set_upper_follower_count(limit = 6500)
#session.set_dont_like('nsfw')
#session.set_dont_like('#exactmatch', '[startswith', ']endswith', 'broadmatch')
session.unfollow_users(amount=500)

#session.follow_by_list(accs, times=1)

session.end()


**Here is the CMD line:**

Logged in successfully!
Number of people followed automatically remaining: 776
--> Ongoing Unfollow 1, now unfollowing: b'amar_tafilovic'
--> Ongoing Unfollow 2, now unfollowing: b'super_car_heaven_'
--> Ongoing Unfollow 3, now unfollowing: b'la2natural'
--> Ongoing Unfollow 4, now unfollowing: b'lusinelusarts'
--> Ongoing Unfollow 5, now unfollowing: b'khfitfam'
--> Ongoing Unfollow 6, now unfollowing: b'nicksforzarealty'
--> Ongoing Unfollow 7, now unfollowing: b'kymu.motivation'
--> Ongoing Unfollow 8, now unfollowing: b'roger.despres'
--> Ongoing Unfollow 9, now unfollowing: b'biene141291'
--> Ongoing Unfollow 10, now unfollowing: b'trendynclassy_acce
sleeping for about 10min
--> Ongoing Unfollow 11, now unfollowing: b'lizzy.pg'
--> Ongoing Unfollow 12, now unfollowing: b'chrisprandy'
--> Ongoing Unfollow 13, now unfollowing: b'faits.n.quotes'
--> Ongoing Unfollow 14, now unfollowing: b'mindsetleader'
--> Ongoing Unfollow 15, now unfollowing: b'55totalpackage55'
--> Ongoing Unfollow 16, now unfollowing: b'sorelleshoes'
--> Ongoing Unfollow 17, now unfollowing: b'babymugglemom'
--> Ongoing Unfollow 18, now unfollowing: b'karrcomedy'
--> Ongoing Unfollow 19, now unfollowing: b'roninisgolden'
--> Total people unfollowed : 19

Session ended
-------------


Thank you in advance,
Jeffrey

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `instapy/unfollow_util.py`
Content:
```
1 """Module which handles the follow features like unfollowing and following"""
2 import json
3 import csv
4 from .time_util import sleep
5 from random import randint
6 from .util import delete_line_from_file
7 from .util import scroll_bottom
8 from .print_log_writer import log_followed_pool
9 
10 
11 def set_automated_followed_pool(username):
12     automatedFollowedPool = []
13     try:
14         with open('./logs/' + username + '_followedPool.csv') as followedPoolFile:
15             reader = csv.reader(followedPoolFile)
16             automatedFollowedPool = [row[0] for row in reader]
17 
18         print("Number of people followed automatically remaining: {}".format(len(automatedFollowedPool)))
19         followedPoolFile.close()
20 
21     except BaseException as e:
22         print("set_automated_followed_pool error \n", str(e))
23 
24     return automatedFollowedPool
25 
26 
27 def unfollow(browser, username, amount, dont_include, onlyInstapyFollowed, automatedFollowedPool):
28     """unfollows the given amount of users"""
29     unfollowNum = 0
30 
31     browser.get('https://www.instagram.com/' + username)
32 
33     #  check how many poeple we are following
34     allfollowing = browser.find_element_by_xpath("//li[3]/a/span").text
35     allfollowing = allfollowing.replace(',', '').replace('.', '')
36     allfollowing = int(allfollowing.replace('k', '00').replace('m', '00000'))
37 
38     #  throw RuntimeWarning if we are 0 people following
39     if (allfollowing == 0):
40         raise RuntimeWarning('There are 0 people to unfollow')
41 
42     try:
43         following_link = browser.find_elements_by_xpath('//header/div[2]//li[3]')
44         following_link[0].click()
45     except BaseException as e:
46         print("following_link error \n", str(e))
47 
48     sleep(2)
49 
50     # find dialog box
51 
52     dialog = browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/div[2]')
53 
54     # scroll down the page
55     scroll_bottom(browser, dialog, allfollowing)
56 
57     # get persons, unfollow buttons, and length of followed pool
58     person_list_a = dialog.find_elements_by_tag_name("a")
59     person_list = []
60 
61     for person in person_list_a:
62 
63         if person and hasattr(person, 'text') and person.text:
64             person_list.append(person.text)
65 
66     follow_buttons = dialog.find_elements_by_tag_name('button')
67     automatedFollowedPoolLength = len(automatedFollowedPool)
68 
69     # unfollow loop
70     try:
71         hasSlept = False
72 
73         for button, person in zip(follow_buttons, person_list):
74             if unfollowNum >= amount:
75                 print("--> Total unfollowNum reached it's amount given ", unfollowNum)
76                 break
77 
78             if onlyInstapyFollowed == True and unfollowNum >= automatedFollowedPoolLength:
79                 print("--> Total unfollowNum exeeded the pool of automated followed ", unfollowNum)
80                 break
81 
82             if unfollowNum != 0 and hasSlept == False and unfollowNum % 10 == 0:
83                 print('sleeping for about 10min')
84                 sleep(600)
85                 hasSlept = True
86                 continue
87 
88             if person not in dont_include:
89                 if onlyInstapyFollowed == True and person in automatedFollowedPool:
90                     unfollowNum += 1
91                     button.click()
92                     delete_line_from_file('./logs/' + username + '_followedPool.csv', person + ",\n")
93 
94                     print('--> Ongoing Unfollow From InstaPy ' + str(unfollowNum) + ', now unfollowing: {}'.format(
95                         person.encode('utf-8')))
96                     sleep(15)
97                     # To only sleep once until there is the next unfollow
98                     if hasSlept: hasSlept = False
99 
100                     continue
101 
102                 elif onlyInstapyFollowed != True:
103                     unfollowNum += 1
104                     button.click()
105 
106                     print('--> Ongoing Unfollow ' + str(unfollowNum) + ', now unfollowing: {}'.format(
107                         person.encode('utf-8')))
108                     sleep(15)
109                     # To only sleep once until there is the next unfollow
110                     if hasSlept: hasSlept = False
111 
112                     continue
113 
114             else:
115                 continue
116 
117     except BaseException as e:
118         print("unfollow loop error \n", str(e))
119 
120     return unfollowNum
121 
122 
123 def follow_user(browser, follow_restrict, login, user_name):
124     """Follows the user of the currently opened image"""
125 
126     follow_button = browser.find_element_by_xpath("//article/header/span/button")
127     sleep(2)
128 
129     if follow_button.text == 'Follow':
130         follow_button.click()
131         print('--> Now following')
132         log_followed_pool(login, user_name)
133         follow_restrict[user_name] = follow_restrict.get(user_name, 0) + 1
134         sleep(3)
135         return 1
136 
137     else:
138         print('--> Already following')
139         sleep(1)
140         return 0
141 
142 
143 def follow_given_user(browser, acc_to_follow, follow_restrict):
144     """Follows a given user."""
145     browser.get('https://www.instagram.com/' + acc_to_follow)
146     print('--> {} instagram account is opened...'.format(acc_to_follow))
147     follow_button = browser.find_element_by_xpath("//*[contains(text(), 'Follow')]")
148     sleep(10)
149     if follow_button.text == 'Follow':
150         follow_button.click()
151         print('---> Now following: {}'.format(acc_to_follow))
152         print('*' * 20)
153         follow_restrict[acc_to_follow] = follow_restrict.get(acc_to_follow, 0) + 1
154         sleep(3)
155         return 1
156     else:
157         print('---> {} is already followed'.format(acc_to_follow))
158         print('*' * 20)
159         sleep(3)
160         return 0
161 
162 
163 def dump_follow_restriction(followRes):
164     """Dumps the given dictionary to a file using the json format"""
165     with open('./logs/followRestriction.json', 'w') as followResFile:
166         json.dump(followRes, followResFile)
167 
168 
169 def load_follow_restriction():
170     """Loads the saved """
171     with open('./logs/followRestriction.json') as followResFile:
172         return json.load(followResFile)
173
```

Path: `instapy/util.py`
Content:
```
1 from .time_util import sleep
2 from random import randint
3 from random import choice
4 
5 
6 def delete_line_from_file(filepath, lineToDelete):
7     try:
8         f = open(filepath, "r")
9         lines = f.readlines()
10         f.close()
11         f = open(filepath, "w")
12 
13         for line in lines:
14 
15             if line != lineToDelete:
16                 f.write(line)
17         f.close()
18     except BaseException as e:
19         print("delete_line_from_file error \n", str(e))
20 
21 
22 def scroll_bottom(browser, element, range_int):
23     # put a limit to the scrolling
24     if range_int > 50: range_int = 1
25 
26     for i in range(int(range_int / 2)):
27         browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", element)
28         sleep(1)
29 
30     return
31
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/instapy/unfollow_util.py b/instapy/unfollow_util.py
--- a/instapy/unfollow_util.py
+++ b/instapy/unfollow_util.py
@@ -49,7 +49,7 @@
 
     # find dialog box
 
-    dialog = browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/div[2]')
+    dialog = browser.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div[2]/div/div[2]')
 
     # scroll down the page
     scroll_bottom(browser, dialog, allfollowing)
diff --git a/instapy/util.py b/instapy/util.py
--- a/instapy/util.py
+++ b/instapy/util.py
@@ -21,7 +21,7 @@
 
 def scroll_bottom(browser, element, range_int):
     # put a limit to the scrolling
-    if range_int > 50: range_int = 1
+    if range_int > 50: range_int = 50
 
     for i in range(int(range_int / 2)):
         browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", element)

{"golden_diff": "diff --git a/instapy/unfollow_util.py b/instapy/unfollow_util.py\n--- a/instapy/unfollow_util.py\n+++ b/instapy/unfollow_util.py\n@@ -49,7 +49,7 @@\n \n     # find dialog box\n \n-    dialog = browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/div[2]')\n+    dialog = browser.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div[2]/div/div[2]')\n \n     # scroll down the page\n     scroll_bottom(browser, dialog, allfollowing)\ndiff --git a/instapy/util.py b/instapy/util.py\n--- a/instapy/util.py\n+++ b/instapy/util.py\n@@ -21,7 +21,7 @@\n \n def scroll_bottom(browser, element, range_int):\n     # put a limit to the scrolling\n-    if range_int > 50: range_int = 1\n+    if range_int > 50: range_int = 50\n \n     for i in range(int(range_int / 2)):\n         browser.execute_script(\"arguments[0].scrollTop = arguments[0].scrollHeight\", element)\n", "issue": "Unfollow end prematurelly \nHello I made the following script, but after it unfollows 19 people it neatly ends the session.\r\nWhy is it ending prematurly? \r\n\r\nfrom instapy import InstaPy\r\nimport os\r\nsession = InstaPy(username='login', password='pass')\r\nsession.login()\r\nsession.set_do_follow(enabled=True, percentage=97, times=1)\r\n##session.set_upper_follower_count(limit = 6500)\r\n#session.set_dont_like('nsfw')\r\n#session.set_dont_like('#exactmatch', '[startswith', ']endswith', 'broadmatch')\r\nsession.unfollow_users(amount=500)\r\n\r\n#session.follow_by_list(accs, times=1)\r\n\r\nsession.end()\r\n\r\n\r\n**Here is the CMD line:**\r\n\r\nLogged in successfully!\r\nNumber of people followed automatically remaining: 776\r\n--> Ongoing Unfollow 1, now unfollowing: b'amar_tafilovic'\r\n--> Ongoing Unfollow 2, now unfollowing: b'super_car_heaven_'\r\n--> Ongoing Unfollow 3, now unfollowing: b'la2natural'\r\n--> Ongoing Unfollow 4, now unfollowing: b'lusinelusarts'\r\n--> Ongoing Unfollow 5, now unfollowing: b'khfitfam'\r\n--> Ongoing Unfollow 6, now unfollowing: b'nicksforzarealty'\r\n--> Ongoing Unfollow 7, now unfollowing: b'kymu.motivation'\r\n--> Ongoing Unfollow 8, now unfollowing: b'roger.despres'\r\n--> Ongoing Unfollow 9, now unfollowing: b'biene141291'\r\n--> Ongoing Unfollow 10, now unfollowing: b'trendynclassy_acce\r\nsleeping for about 10min\r\n--> Ongoing Unfollow 11, now unfollowing: b'lizzy.pg'\r\n--> Ongoing Unfollow 12, now unfollowing: b'chrisprandy'\r\n--> Ongoing Unfollow 13, now unfollowing: b'faits.n.quotes'\r\n--> Ongoing Unfollow 14, now unfollowing: b'mindsetleader'\r\n--> Ongoing Unfollow 15, now unfollowing: b'55totalpackage55'\r\n--> Ongoing Unfollow 16, now unfollowing: b'sorelleshoes'\r\n--> Ongoing Unfollow 17, now unfollowing: b'babymugglemom'\r\n--> Ongoing Unfollow 18, now unfollowing: b'karrcomedy'\r\n--> Ongoing Unfollow 19, now unfollowing: b'roninisgolden'\r\n--> Total people unfollowed : 19\r\n\r\nSession ended\r\n-------------\r\n\r\n\r\nThank you in advance,\r\nJeffrey\n", "before_files": [{"content": "\"\"\"Module which handles the follow features like unfollowing and following\"\"\"\nimport json\nimport csv\nfrom .time_util import sleep\nfrom random import randint\nfrom .util import delete_line_from_file\nfrom .util import scroll_bottom\nfrom .print_log_writer import log_followed_pool\n\n\ndef set_automated_followed_pool(username):\n    automatedFollowedPool = []\n    try:\n        with open('./logs/' + username + '_followedPool.csv') as followedPoolFile:\n            reader = csv.reader(followedPoolFile)\n            automatedFollowedPool = [row[0] for row in reader]\n\n        print(\"Number of people followed automatically remaining: {}\".format(len(automatedFollowedPool)))\n        followedPoolFile.close()\n\n    except BaseException as e:\n        print(\"set_automated_followed_pool error \\n\", str(e))\n\n    return automatedFollowedPool\n\n\ndef unfollow(browser, username, amount, dont_include, onlyInstapyFollowed, automatedFollowedPool):\n    \"\"\"unfollows the given amount of users\"\"\"\n    unfollowNum = 0\n\n    browser.get('https://www.instagram.com/' + username)\n\n    #  check how many poeple we are following\n    allfollowing = browser.find_element_by_xpath(\"//li[3]/a/span\").text\n    allfollowing = allfollowing.replace(',', '').replace('.', '')\n    allfollowing = int(allfollowing.replace('k', '00').replace('m', '00000'))\n\n    #  throw RuntimeWarning if we are 0 people following\n    if (allfollowing == 0):\n        raise RuntimeWarning('There are 0 people to unfollow')\n\n    try:\n        following_link = browser.find_elements_by_xpath('//header/div[2]//li[3]')\n        following_link[0].click()\n    except BaseException as e:\n        print(\"following_link error \\n\", str(e))\n\n    sleep(2)\n\n    # find dialog box\n\n    dialog = browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/div[2]')\n\n    # scroll down the page\n    scroll_bottom(browser, dialog, allfollowing)\n\n    # get persons, unfollow buttons, and length of followed pool\n    person_list_a = dialog.find_elements_by_tag_name(\"a\")\n    person_list = []\n\n    for person in person_list_a:\n\n        if person and hasattr(person, 'text') and person.text:\n            person_list.append(person.text)\n\n    follow_buttons = dialog.find_elements_by_tag_name('button')\n    automatedFollowedPoolLength = len(automatedFollowedPool)\n\n    # unfollow loop\n    try:\n        hasSlept = False\n\n        for button, person in zip(follow_buttons, person_list):\n            if unfollowNum >= amount:\n                print(\"--> Total unfollowNum reached it's amount given \", unfollowNum)\n                break\n\n            if onlyInstapyFollowed == True and unfollowNum >= automatedFollowedPoolLength:\n                print(\"--> Total unfollowNum exeeded the pool of automated followed \", unfollowNum)\n                break\n\n            if unfollowNum != 0 and hasSlept == False and unfollowNum % 10 == 0:\n                print('sleeping for about 10min')\n                sleep(600)\n                hasSlept = True\n                continue\n\n            if person not in dont_include:\n                if onlyInstapyFollowed == True and person in automatedFollowedPool:\n                    unfollowNum += 1\n                    button.click()\n                    delete_line_from_file('./logs/' + username + '_followedPool.csv', person + \",\\n\")\n\n                    print('--> Ongoing Unfollow From InstaPy ' + str(unfollowNum) + ', now unfollowing: {}'.format(\n                        person.encode('utf-8')))\n                    sleep(15)\n                    # To only sleep once until there is the next unfollow\n                    if hasSlept: hasSlept = False\n\n                    continue\n\n                elif onlyInstapyFollowed != True:\n                    unfollowNum += 1\n                    button.click()\n\n                    print('--> Ongoing Unfollow ' + str(unfollowNum) + ', now unfollowing: {}'.format(\n                        person.encode('utf-8')))\n                    sleep(15)\n                    # To only sleep once until there is the next unfollow\n                    if hasSlept: hasSlept = False\n\n                    continue\n\n            else:\n                continue\n\n    except BaseException as e:\n        print(\"unfollow loop error \\n\", str(e))\n\n    return unfollowNum\n\n\ndef follow_user(browser, follow_restrict, login, user_name):\n    \"\"\"Follows the user of the currently opened image\"\"\"\n\n    follow_button = browser.find_element_by_xpath(\"//article/header/span/button\")\n    sleep(2)\n\n    if follow_button.text == 'Follow':\n        follow_button.click()\n        print('--> Now following')\n        log_followed_pool(login, user_name)\n        follow_restrict[user_name] = follow_restrict.get(user_name, 0) + 1\n        sleep(3)\n        return 1\n\n    else:\n        print('--> Already following')\n        sleep(1)\n        return 0\n\n\ndef follow_given_user(browser, acc_to_follow, follow_restrict):\n    \"\"\"Follows a given user.\"\"\"\n    browser.get('https://www.instagram.com/' + acc_to_follow)\n    print('--> {} instagram account is opened...'.format(acc_to_follow))\n    follow_button = browser.find_element_by_xpath(\"//*[contains(text(), 'Follow')]\")\n    sleep(10)\n    if follow_button.text == 'Follow':\n        follow_button.click()\n        print('---> Now following: {}'.format(acc_to_follow))\n        print('*' * 20)\n        follow_restrict[acc_to_follow] = follow_restrict.get(acc_to_follow, 0) + 1\n        sleep(3)\n        return 1\n    else:\n        print('---> {} is already followed'.format(acc_to_follow))\n        print('*' * 20)\n        sleep(3)\n        return 0\n\n\ndef dump_follow_restriction(followRes):\n    \"\"\"Dumps the given dictionary to a file using the json format\"\"\"\n    with open('./logs/followRestriction.json', 'w') as followResFile:\n        json.dump(followRes, followResFile)\n\n\ndef load_follow_restriction():\n    \"\"\"Loads the saved \"\"\"\n    with open('./logs/followRestriction.json') as followResFile:\n        return json.load(followResFile)\n", "path": "instapy/unfollow_util.py"}, {"content": "from .time_util import sleep\nfrom random import randint\nfrom random import choice\n\n\ndef delete_line_from_file(filepath, lineToDelete):\n    try:\n        f = open(filepath, \"r\")\n        lines = f.readlines()\n        f.close()\n        f = open(filepath, \"w\")\n\n        for line in lines:\n\n            if line != lineToDelete:\n                f.write(line)\n        f.close()\n    except BaseException as e:\n        print(\"delete_line_from_file error \\n\", str(e))\n\n\ndef scroll_bottom(browser, element, range_int):\n    # put a limit to the scrolling\n    if range_int > 50: range_int = 1\n\n    for i in range(int(range_int / 2)):\n        browser.execute_script(\"arguments[0].scrollTop = arguments[0].scrollHeight\", element)\n        sleep(1)\n\n    return\n", "path": "instapy/util.py"}], "after_files": [{"content": "\"\"\"Module which handles the follow features like unfollowing and following\"\"\"\nimport json\nimport csv\nfrom .time_util import sleep\nfrom random import randint\nfrom .util import delete_line_from_file\nfrom .util import scroll_bottom\nfrom .print_log_writer import log_followed_pool\n\n\ndef set_automated_followed_pool(username):\n    automatedFollowedPool = []\n    try:\n        with open('./logs/' + username + '_followedPool.csv') as followedPoolFile:\n            reader = csv.reader(followedPoolFile)\n            automatedFollowedPool = [row[0] for row in reader]\n\n        print(\"Number of people followed automatically remaining: {}\".format(len(automatedFollowedPool)))\n        followedPoolFile.close()\n\n    except BaseException as e:\n        print(\"set_automated_followed_pool error \\n\", str(e))\n\n    return automatedFollowedPool\n\n\ndef unfollow(browser, username, amount, dont_include, onlyInstapyFollowed, automatedFollowedPool):\n    \"\"\"unfollows the given amount of users\"\"\"\n    unfollowNum = 0\n\n    browser.get('https://www.instagram.com/' + username)\n\n    #  check how many poeple we are following\n    allfollowing = browser.find_element_by_xpath(\"//li[3]/a/span\").text\n    allfollowing = allfollowing.replace(',', '').replace('.', '')\n    allfollowing = int(allfollowing.replace('k', '00').replace('m', '00000'))\n\n    #  throw RuntimeWarning if we are 0 people following\n    if (allfollowing == 0):\n        raise RuntimeWarning('There are 0 people to unfollow')\n\n    try:\n        following_link = browser.find_elements_by_xpath('//header/div[2]//li[3]')\n        following_link[0].click()\n    except BaseException as e:\n        print(\"following_link error \\n\", str(e))\n\n    sleep(2)\n\n    # find dialog box\n\n    dialog = browser.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div[2]/div/div[2]')\n\n    # scroll down the page\n    scroll_bottom(browser, dialog, allfollowing)\n\n    # get persons, unfollow buttons, and length of followed pool\n    person_list_a = dialog.find_elements_by_tag_name(\"a\")\n    person_list = []\n\n    for person in person_list_a:\n\n        if person and hasattr(person, 'text') and person.text:\n            person_list.append(person.text)\n\n    follow_buttons = dialog.find_elements_by_tag_name('button')\n    automatedFollowedPoolLength = len(automatedFollowedPool)\n\n    # unfollow loop\n    try:\n        hasSlept = False\n\n        for button, person in zip(follow_buttons, person_list):\n            if unfollowNum >= amount:\n                print(\"--> Total unfollowNum reached it's amount given \", unfollowNum)\n                break\n\n            if onlyInstapyFollowed == True and unfollowNum >= automatedFollowedPoolLength:\n                print(\"--> Total unfollowNum exeeded the pool of automated followed \", unfollowNum)\n                break\n\n            if unfollowNum != 0 and hasSlept == False and unfollowNum % 10 == 0:\n                print('sleeping for about 10min')\n                sleep(600)\n                hasSlept = True\n                continue\n\n            if person not in dont_include:\n                if onlyInstapyFollowed == True and person in automatedFollowedPool:\n                    unfollowNum += 1\n                    button.click()\n                    delete_line_from_file('./logs/' + username + '_followedPool.csv', person + \",\\n\")\n\n                    print('--> Ongoing Unfollow From InstaPy ' + str(unfollowNum) + ', now unfollowing: {}'.format(\n                        person.encode('utf-8')))\n                    sleep(15)\n                    # To only sleep once until there is the next unfollow\n                    if hasSlept: hasSlept = False\n\n                    continue\n\n                elif onlyInstapyFollowed != True:\n                    unfollowNum += 1\n                    button.click()\n\n                    print('--> Ongoing Unfollow ' + str(unfollowNum) + ', now unfollowing: {}'.format(\n                        person.encode('utf-8')))\n                    sleep(15)\n                    # To only sleep once until there is the next unfollow\n                    if hasSlept: hasSlept = False\n\n                    continue\n\n            else:\n                continue\n\n    except BaseException as e:\n        print(\"unfollow loop error \\n\", str(e))\n\n    return unfollowNum\n\n\ndef follow_user(browser, follow_restrict, login, user_name):\n    \"\"\"Follows the user of the currently opened image\"\"\"\n\n    follow_button = browser.find_element_by_xpath(\"//article/header/span/button\")\n    sleep(2)\n\n    if follow_button.text == 'Follow':\n        follow_button.click()\n        print('--> Now following')\n        log_followed_pool(login, user_name)\n        follow_restrict[user_name] = follow_restrict.get(user_name, 0) + 1\n        sleep(3)\n        return 1\n\n    else:\n        print('--> Already following')\n        sleep(1)\n        return 0\n\n\ndef follow_given_user(browser, acc_to_follow, follow_restrict):\n    \"\"\"Follows a given user.\"\"\"\n    browser.get('https://www.instagram.com/' + acc_to_follow)\n    print('--> {} instagram account is opened...'.format(acc_to_follow))\n    follow_button = browser.find_element_by_xpath(\"//*[contains(text(), 'Follow')]\")\n    sleep(10)\n    if follow_button.text == 'Follow':\n        follow_button.click()\n        print('---> Now following: {}'.format(acc_to_follow))\n        print('*' * 20)\n        follow_restrict[acc_to_follow] = follow_restrict.get(acc_to_follow, 0) + 1\n        sleep(3)\n        return 1\n    else:\n        print('---> {} is already followed'.format(acc_to_follow))\n        print('*' * 20)\n        sleep(3)\n        return 0\n\n\ndef dump_follow_restriction(followRes):\n    \"\"\"Dumps the given dictionary to a file using the json format\"\"\"\n    with open('./logs/followRestriction.json', 'w') as followResFile:\n        json.dump(followRes, followResFile)\n\n\ndef load_follow_restriction():\n    \"\"\"Loads the saved \"\"\"\n    with open('./logs/followRestriction.json') as followResFile:\n        return json.load(followResFile)\n", "path": "instapy/unfollow_util.py"}, {"content": "from .time_util import sleep\nfrom random import randint\nfrom random import choice\n\n\ndef delete_line_from_file(filepath, lineToDelete):\n    try:\n        f = open(filepath, \"r\")\n        lines = f.readlines()\n        f.close()\n        f = open(filepath, \"w\")\n\n        for line in lines:\n\n            if line != lineToDelete:\n                f.write(line)\n        f.close()\n    except BaseException as e:\n        print(\"delete_line_from_file error \\n\", str(e))\n\n\ndef scroll_bottom(browser, element, range_int):\n    # put a limit to the scrolling\n    if range_int > 50: range_int = 50\n\n    for i in range(int(range_int / 2)):\n        browser.execute_script(\"arguments[0].scrollTop = arguments[0].scrollHeight\", element)\n        sleep(1)\n\n    return\n", "path": "instapy/util.py"}]}