We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Pagination not working (I got a quick fix-- class was renamed)
Hey the "load more" button class was renamed yielding this error: 'Load button not found, working with current images!'

The issue was a class name change for the "load more"button. I fixed my bot by updating instapy/like_util.py both lines 35 and 115 (they were identical) from:
('//a[contains(@class, "_8imhp _glz1g")]')

to:
('//a[contains(@class, "_1cr2e _epyes")]')
Pagination not working (I got a quick fix-- class was renamed)
Hey the "load more" button class was renamed yielding this error: 'Load button not found, working with current images!'

The issue was a class name change for the "load more"button. I fixed my bot by updating instapy/like_util.py both lines 35 and 115 (they were identical) from:
('//a[contains(@class, "_8imhp _glz1g")]')

to:
('//a[contains(@class, "_1cr2e _epyes")]')

--- 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/like_util.py`
Content:
```
1 import re
2 
3 """Module that handles the like features"""
4 from math import ceil
5 from re import findall
6 from selenium.webdriver.common.keys import Keys
7 
8 from .time_util import sleep
9 
10 
11 def get_links_for_location(browser, location, amount, media=None):
12     """Fetches the number of links specified
13     by amount and returns a list of links"""
14     if media is None:
15         # All known media types
16         media = ['', 'Post', 'Video']
17     elif media == 'Photo':
18         # Include posts with multiple images in it
19         media = ['', 'Post']
20     else:
21         # Make it an array to use it in the following part
22         media = [media]
23 
24     browser.get('https://www.instagram.com/explore/locations/'
25                 + location)
26     sleep(2)
27 
28     # clicking load more
29     body_elem = browser.find_element_by_tag_name('body')
30     sleep(2)
31 
32     abort = True
33     try:
34         load_button = body_elem.find_element_by_xpath \
35             ('//a[contains(@class, "_8imhp _glz1g")]')
36     except:
37         print('Load button not found, working with current images!')
38     else:
39         abort = False
40         body_elem.send_keys(Keys.END)
41         sleep(2)
42         load_button.click()
43 
44     body_elem.send_keys(Keys.HOME)
45     sleep(1)
46 
47     # Get links
48     main_elem = browser.find_element_by_tag_name('main')
49     link_elems = main_elem.find_elements_by_tag_name('a')
50     total_links = len(link_elems)
51     links = [link_elem.get_attribute('href') for link_elem in link_elems
52              if link_elem.text in media]
53     filtered_links = len(links)
54 
55     while (filtered_links < amount) and not abort:
56         amount_left = amount - filtered_links
57         # Average items of the right media per page loaded
58         new_per_page = ceil(12 * filtered_links / total_links)
59         if new_per_page == 0:
60             # Avoid division by zero
61             new_per_page = 1. / 12.
62         # Number of page load needed
63         new_needed = int(ceil(amount_left / new_per_page))
64 
65         if new_needed > 12:
66             # Don't go bananas trying to get all of instagram!
67             new_needed = 12
68 
69         for i in range(new_needed):  # add images x * 12
70             # Keep the latest window active while loading more posts
71             before_load = total_links
72             body_elem.send_keys(Keys.END)
73             sleep(1)
74             body_elem.send_keys(Keys.HOME)
75             sleep(1)
76             link_elems = main_elem.find_elements_by_tag_name('a')
77             total_links = len(link_elems)
78             abort = (before_load == total_links)
79             if abort:
80                 break
81 
82         links = [link_elem.get_attribute('href') for link_elem in link_elems
83                  if link_elem.text in media]
84         filtered_links = len(links)
85 
86     return links[:amount]
87 
88 
89 def get_links_for_tag(browser, tag, amount, media=None):
90     """Fetches the number of links specified
91     by amount and returns a list of links"""
92     if media is None:
93         # All known media types
94         media = ['', 'Post', 'Video']
95     elif media == 'Photo':
96         # Include posts with multiple images in it
97         media = ['', 'Post']
98     else:
99         # Make it an array to use it in the following part
100         media = [media]
101 
102     browser.get('https://www.instagram.com/explore/tags/'
103                 + (tag[1:] if tag[:1] == '#' else tag))
104     sleep(2)
105 
106     # clicking load more
107     body_elem = browser.find_element_by_tag_name('body')
108     sleep(2)
109 
110     abort = True
111     try:
112         load_button = body_elem.find_element_by_xpath \
113             ('//a[contains(@class, "_8imhp _glz1g")]')
114     except:
115         print('Load button not found, working with current images!')
116     else:
117         abort = False
118         body_elem.send_keys(Keys.END)
119         sleep(2)
120         load_button.click()
121 
122     body_elem.send_keys(Keys.HOME)
123     sleep(1)
124 
125     # Get links
126     main_elem = browser.find_element_by_tag_name('main')
127     link_elems = main_elem.find_elements_by_tag_name('a')
128     total_links = len(link_elems)
129     links = []
130     filtered_links = 0
131     try:
132         if link_elems:
133             links = [link_elem.get_attribute('href') for link_elem in link_elems
134                      if link_elem and link_elem.text in media]
135             filtered_links = len(links)
136 
137     except BaseException as e:
138         print("link_elems error \n", str(e))
139 
140     while (filtered_links < amount) and not abort:
141         amount_left = amount - filtered_links
142         # Average items of the right media per page loaded
143         new_per_page = ceil(12 * filtered_links / total_links)
144         if new_per_page == 0:
145             # Avoid division by zero
146             new_per_page = 1. / 12.
147         # Number of page load needed
148         new_needed = int(ceil(amount_left / new_per_page))
149 
150         if new_needed > 12:
151             # Don't go bananas trying to get all of instagram!
152             new_needed = 12
153 
154         for i in range(new_needed):  # add images x * 12
155             # Keep the latest window active while loading more posts
156             before_load = total_links
157             body_elem.send_keys(Keys.END)
158             sleep(1)
159             body_elem.send_keys(Keys.HOME)
160             sleep(1)
161             link_elems = main_elem.find_elements_by_tag_name('a')
162             total_links = len(link_elems)
163             abort = (before_load == total_links)
164             if abort:
165                 break
166 
167         links = [link_elem.get_attribute('href') for link_elem in link_elems
168                  if link_elem.text in media]
169         filtered_links = len(links)
170 
171     return links[:amount]
172 
173 
174 def check_link(browser, link, dont_like, ignore_if_contains, ignore_users,
175                username, like_by_followers_upper_limit, like_by_followers_lower_limit):
176     browser.get(link)
177     sleep(2)
178 
179     """Check if the Post is Valid/Exists"""
180     post_page = browser.execute_script("return window._sharedData.entry_data.PostPage")
181     if post_page is None:
182         print('Unavailable Page: {}'.format(link.encode('utf-8')))
183         return True, None, None, 'Unavailable Page'
184 
185     """Gets the description of the link and checks for the dont_like tags"""
186     graphql = 'graphql' in post_page[0]
187     if graphql:
188         media = post_page[0]['graphql']['shortcode_media']
189         is_video = media['is_video']
190         user_name = media['owner']['username']
191         image_text = media['edge_media_to_caption']['edges']
192         image_text = image_text[0]['node']['text'] if image_text else None
193         owner_comments = browser.execute_script('''
194       latest_comments = window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.edge_media_to_comment.edges;
195       if (latest_comments === undefined) latest_comments = Array();
196       owner_comments = latest_comments
197         .filter(item => item.node.owner.username == '{}')
198         .map(item => item.node.text)
199         .reduce((item, total) => item + '\\n' + total, '');
200       return owner_comments;
201     '''.format(user_name))
202     else:
203         media = post_page[0]['media']
204         is_video = media['is_video']
205         user_name = media['owner']['username']
206         image_text = media['caption']
207         owner_comments = browser.execute_script('''
208       latest_comments = window._sharedData.entry_data.PostPage[0].media.comments.nodes;
209       if (latest_comments === undefined) latest_comments = Array();
210       owner_comments = latest_comments
211         .filter(item => item.user.username == '{}')
212         .map(item => item.text)
213         .reduce((item, total) => item + '\\n' + total, '');
214       return owner_comments;
215     '''.format(user_name))
216 
217     if owner_comments == '':
218         owner_comments = None
219 
220     """Append owner comments to description as it might contain further tags"""
221     if image_text is None:
222         image_text = owner_comments
223     elif owner_comments:
224         image_text = image_text + '\n' + owner_comments
225 
226     """If the image still has no description gets the first comment"""
227     if image_text is None:
228         if graphql:
229             image_text = media['edge_media_to_comment']['edges']
230             image_text = image_text[0]['node']['text'] if image_text else None
231         else:
232             image_text = media['comments']['nodes']
233             image_text = image_text[0]['text'] if image_text else None
234     if image_text is None:
235         image_text = "No description"
236 
237     print('Image from: {}'.format(user_name.encode('utf-8')))
238 
239     """Find the number of followes the user has"""
240     if like_by_followers_upper_limit or like_by_followers_lower_limit:
241         userlink = 'https://www.instagram.com/' + user_name
242         browser.get(userlink)
243         sleep(1)
244         num_followers = browser.execute_script(
245             "return window._sharedData.entry_data.ProfilePage[0].user.followed_by.count")
246         browser.get(link)
247         sleep(1)
248         print('Number of Followers: {}'.format(num_followers))
249 
250         if like_by_followers_upper_limit and num_followers > like_by_followers_upper_limit:
251             return True, user_name, is_video, 'Number of followers exceeds limit'
252         if like_by_followers_lower_limit and num_followers < like_by_followers_lower_limit:
253             return True, user_name, is_video, 'Number of followers does not reach minimum'
254 
255     print('Link: {}'.format(link.encode('utf-8')))
256     print('Description: {}'.format(image_text.encode('utf-8')))
257 
258     """Check if the user_name is in the ignore_users list"""
259     if (user_name in ignore_users) or (user_name == username):
260         return True, user_name, is_video, 'Username'
261 
262     if any((word in image_text for word in ignore_if_contains)):
263         return False, user_name, is_video, 'None'
264 
265     dont_like_regex = []
266 
267     for dont_likes in dont_like:
268         if dont_likes.startswith("#"):
269             dont_like_regex.append(dont_likes + "([^\d\w]|$)")
270         elif dont_likes.startswith("["):
271             dont_like_regex.append("#" + dont_likes[1:] + "[\d\w]+([^\d\w]|$)")
272         elif dont_likes.startswith("]"):
273             dont_like_regex.append("#[\d\w]+" + dont_likes[1:] + "([^\d\w]|$)")
274         else:
275             dont_like_regex.append("#[\d\w]*" + dont_likes + "[\d\w]*([^\d\w]|$)")
276 
277     for dont_likes_regex in dont_like_regex:
278         if re.search(dont_likes_regex, image_text, re.IGNORECASE):
279             return True, user_name, is_video, 'Inappropriate'
280 
281     return False, user_name, is_video, 'None'
282 
283 
284 def like_image(browser):
285     """Likes the browser opened image"""
286     like_elem = browser.find_elements_by_xpath("//a[@role = 'button']/span[text()='Like']")
287     liked_elem = browser.find_elements_by_xpath("//a[@role = 'button']/span[text()='Unlike']")
288 
289     if len(like_elem) == 1:
290         browser.execute_script(
291             "document.getElementsByClassName('" + like_elem[0].get_attribute("class") + "')[0].click()")
292         print('--> Image Liked!')
293         sleep(2)
294         return True
295     elif len(liked_elem) == 1:
296         print('--> Already Liked!')
297         return False
298     else:
299         print('--> Invalid Like Element!')
300         return False
301 
302 
303 def get_tags(browser, url):
304     """Gets all the tags of the given description in the url"""
305     browser.get(url)
306     sleep(1)
307 
308     graphql = browser.execute_script("return ('graphql' in window._sharedData.entry_data.PostPage[0])")
309     if graphql:
310         image_text = browser.execute_script(
311             "return window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.edge_media_to_caption.edges[0].node.text")
312     else:
313         image_text = browser.execute_script("return window._sharedData.entry_data.PostPage[0].media.caption.text")
314 
315     tags = findall(r'#\w*', image_text)
316     return tags
317
```
--- 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/like_util.py b/instapy/like_util.py
--- a/instapy/like_util.py
+++ b/instapy/like_util.py
@@ -32,7 +32,7 @@
     abort = True
     try:
         load_button = body_elem.find_element_by_xpath \
-            ('//a[contains(@class, "_8imhp _glz1g")]')
+            ('//a[contains(@class, "_1cr2e _epyes")]')
     except:
         print('Load button not found, working with current images!')
     else:
@@ -110,7 +110,7 @@
     abort = True
     try:
         load_button = body_elem.find_element_by_xpath \
-            ('//a[contains(@class, "_8imhp _glz1g")]')
+            ('//a[contains(@class, "_1cr2e _epyes")]')
     except:
         print('Load button not found, working with current images!')
     else:

{"golden_diff": "diff --git a/instapy/like_util.py b/instapy/like_util.py\n--- a/instapy/like_util.py\n+++ b/instapy/like_util.py\n@@ -32,7 +32,7 @@\n     abort = True\n     try:\n         load_button = body_elem.find_element_by_xpath \\\n-            ('//a[contains(@class, \"_8imhp _glz1g\")]')\n+            ('//a[contains(@class, \"_1cr2e _epyes\")]')\n     except:\n         print('Load button not found, working with current images!')\n     else:\n@@ -110,7 +110,7 @@\n     abort = True\n     try:\n         load_button = body_elem.find_element_by_xpath \\\n-            ('//a[contains(@class, \"_8imhp _glz1g\")]')\n+            ('//a[contains(@class, \"_1cr2e _epyes\")]')\n     except:\n         print('Load button not found, working with current images!')\n     else:\n", "issue": "Pagination not working (I got a quick fix-- class was renamed)\nHey the \"load more\" button class was renamed yielding this error: 'Load button not found, working with current images!'\r\n\r\nThe issue was a class name change for the \"load more\"button. I fixed my bot by updating instapy/like_util.py both lines 35 and 115 (they were identical) from:\r\n('//a[contains(@class, \"_8imhp _glz1g\")]')\r\n\r\nto:\r\n('//a[contains(@class, \"_1cr2e _epyes\")]')\nPagination not working (I got a quick fix-- class was renamed)\nHey the \"load more\" button class was renamed yielding this error: 'Load button not found, working with current images!'\r\n\r\nThe issue was a class name change for the \"load more\"button. I fixed my bot by updating instapy/like_util.py both lines 35 and 115 (they were identical) from:\r\n('//a[contains(@class, \"_8imhp _glz1g\")]')\r\n\r\nto:\r\n('//a[contains(@class, \"_1cr2e _epyes\")]')\n", "before_files": [{"content": "import re\n\n\"\"\"Module that handles the like features\"\"\"\nfrom math import ceil\nfrom re import findall\nfrom selenium.webdriver.common.keys import Keys\n\nfrom .time_util import sleep\n\n\ndef get_links_for_location(browser, location, amount, media=None):\n    \"\"\"Fetches the number of links specified\n    by amount and returns a list of links\"\"\"\n    if media is None:\n        # All known media types\n        media = ['', 'Post', 'Video']\n    elif media == 'Photo':\n        # Include posts with multiple images in it\n        media = ['', 'Post']\n    else:\n        # Make it an array to use it in the following part\n        media = [media]\n\n    browser.get('https://www.instagram.com/explore/locations/'\n                + location)\n    sleep(2)\n\n    # clicking load more\n    body_elem = browser.find_element_by_tag_name('body')\n    sleep(2)\n\n    abort = True\n    try:\n        load_button = body_elem.find_element_by_xpath \\\n            ('//a[contains(@class, \"_8imhp _glz1g\")]')\n    except:\n        print('Load button not found, working with current images!')\n    else:\n        abort = False\n        body_elem.send_keys(Keys.END)\n        sleep(2)\n        load_button.click()\n\n    body_elem.send_keys(Keys.HOME)\n    sleep(1)\n\n    # Get links\n    main_elem = browser.find_element_by_tag_name('main')\n    link_elems = main_elem.find_elements_by_tag_name('a')\n    total_links = len(link_elems)\n    links = [link_elem.get_attribute('href') for link_elem in link_elems\n             if link_elem.text in media]\n    filtered_links = len(links)\n\n    while (filtered_links < amount) and not abort:\n        amount_left = amount - filtered_links\n        # Average items of the right media per page loaded\n        new_per_page = ceil(12 * filtered_links / total_links)\n        if new_per_page == 0:\n            # Avoid division by zero\n            new_per_page = 1. / 12.\n        # Number of page load needed\n        new_needed = int(ceil(amount_left / new_per_page))\n\n        if new_needed > 12:\n            # Don't go bananas trying to get all of instagram!\n            new_needed = 12\n\n        for i in range(new_needed):  # add images x * 12\n            # Keep the latest window active while loading more posts\n            before_load = total_links\n            body_elem.send_keys(Keys.END)\n            sleep(1)\n            body_elem.send_keys(Keys.HOME)\n            sleep(1)\n            link_elems = main_elem.find_elements_by_tag_name('a')\n            total_links = len(link_elems)\n            abort = (before_load == total_links)\n            if abort:\n                break\n\n        links = [link_elem.get_attribute('href') for link_elem in link_elems\n                 if link_elem.text in media]\n        filtered_links = len(links)\n\n    return links[:amount]\n\n\ndef get_links_for_tag(browser, tag, amount, media=None):\n    \"\"\"Fetches the number of links specified\n    by amount and returns a list of links\"\"\"\n    if media is None:\n        # All known media types\n        media = ['', 'Post', 'Video']\n    elif media == 'Photo':\n        # Include posts with multiple images in it\n        media = ['', 'Post']\n    else:\n        # Make it an array to use it in the following part\n        media = [media]\n\n    browser.get('https://www.instagram.com/explore/tags/'\n                + (tag[1:] if tag[:1] == '#' else tag))\n    sleep(2)\n\n    # clicking load more\n    body_elem = browser.find_element_by_tag_name('body')\n    sleep(2)\n\n    abort = True\n    try:\n        load_button = body_elem.find_element_by_xpath \\\n            ('//a[contains(@class, \"_8imhp _glz1g\")]')\n    except:\n        print('Load button not found, working with current images!')\n    else:\n        abort = False\n        body_elem.send_keys(Keys.END)\n        sleep(2)\n        load_button.click()\n\n    body_elem.send_keys(Keys.HOME)\n    sleep(1)\n\n    # Get links\n    main_elem = browser.find_element_by_tag_name('main')\n    link_elems = main_elem.find_elements_by_tag_name('a')\n    total_links = len(link_elems)\n    links = []\n    filtered_links = 0\n    try:\n        if link_elems:\n            links = [link_elem.get_attribute('href') for link_elem in link_elems\n                     if link_elem and link_elem.text in media]\n            filtered_links = len(links)\n\n    except BaseException as e:\n        print(\"link_elems error \\n\", str(e))\n\n    while (filtered_links < amount) and not abort:\n        amount_left = amount - filtered_links\n        # Average items of the right media per page loaded\n        new_per_page = ceil(12 * filtered_links / total_links)\n        if new_per_page == 0:\n            # Avoid division by zero\n            new_per_page = 1. / 12.\n        # Number of page load needed\n        new_needed = int(ceil(amount_left / new_per_page))\n\n        if new_needed > 12:\n            # Don't go bananas trying to get all of instagram!\n            new_needed = 12\n\n        for i in range(new_needed):  # add images x * 12\n            # Keep the latest window active while loading more posts\n            before_load = total_links\n            body_elem.send_keys(Keys.END)\n            sleep(1)\n            body_elem.send_keys(Keys.HOME)\n            sleep(1)\n            link_elems = main_elem.find_elements_by_tag_name('a')\n            total_links = len(link_elems)\n            abort = (before_load == total_links)\n            if abort:\n                break\n\n        links = [link_elem.get_attribute('href') for link_elem in link_elems\n                 if link_elem.text in media]\n        filtered_links = len(links)\n\n    return links[:amount]\n\n\ndef check_link(browser, link, dont_like, ignore_if_contains, ignore_users,\n               username, like_by_followers_upper_limit, like_by_followers_lower_limit):\n    browser.get(link)\n    sleep(2)\n\n    \"\"\"Check if the Post is Valid/Exists\"\"\"\n    post_page = browser.execute_script(\"return window._sharedData.entry_data.PostPage\")\n    if post_page is None:\n        print('Unavailable Page: {}'.format(link.encode('utf-8')))\n        return True, None, None, 'Unavailable Page'\n\n    \"\"\"Gets the description of the link and checks for the dont_like tags\"\"\"\n    graphql = 'graphql' in post_page[0]\n    if graphql:\n        media = post_page[0]['graphql']['shortcode_media']\n        is_video = media['is_video']\n        user_name = media['owner']['username']\n        image_text = media['edge_media_to_caption']['edges']\n        image_text = image_text[0]['node']['text'] if image_text else None\n        owner_comments = browser.execute_script('''\n      latest_comments = window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.edge_media_to_comment.edges;\n      if (latest_comments === undefined) latest_comments = Array();\n      owner_comments = latest_comments\n        .filter(item => item.node.owner.username == '{}')\n        .map(item => item.node.text)\n        .reduce((item, total) => item + '\\\\n' + total, '');\n      return owner_comments;\n    '''.format(user_name))\n    else:\n        media = post_page[0]['media']\n        is_video = media['is_video']\n        user_name = media['owner']['username']\n        image_text = media['caption']\n        owner_comments = browser.execute_script('''\n      latest_comments = window._sharedData.entry_data.PostPage[0].media.comments.nodes;\n      if (latest_comments === undefined) latest_comments = Array();\n      owner_comments = latest_comments\n        .filter(item => item.user.username == '{}')\n        .map(item => item.text)\n        .reduce((item, total) => item + '\\\\n' + total, '');\n      return owner_comments;\n    '''.format(user_name))\n\n    if owner_comments == '':\n        owner_comments = None\n\n    \"\"\"Append owner comments to description as it might contain further tags\"\"\"\n    if image_text is None:\n        image_text = owner_comments\n    elif owner_comments:\n        image_text = image_text + '\\n' + owner_comments\n\n    \"\"\"If the image still has no description gets the first comment\"\"\"\n    if image_text is None:\n        if graphql:\n            image_text = media['edge_media_to_comment']['edges']\n            image_text = image_text[0]['node']['text'] if image_text else None\n        else:\n            image_text = media['comments']['nodes']\n            image_text = image_text[0]['text'] if image_text else None\n    if image_text is None:\n        image_text = \"No description\"\n\n    print('Image from: {}'.format(user_name.encode('utf-8')))\n\n    \"\"\"Find the number of followes the user has\"\"\"\n    if like_by_followers_upper_limit or like_by_followers_lower_limit:\n        userlink = 'https://www.instagram.com/' + user_name\n        browser.get(userlink)\n        sleep(1)\n        num_followers = browser.execute_script(\n            \"return window._sharedData.entry_data.ProfilePage[0].user.followed_by.count\")\n        browser.get(link)\n        sleep(1)\n        print('Number of Followers: {}'.format(num_followers))\n\n        if like_by_followers_upper_limit and num_followers > like_by_followers_upper_limit:\n            return True, user_name, is_video, 'Number of followers exceeds limit'\n        if like_by_followers_lower_limit and num_followers < like_by_followers_lower_limit:\n            return True, user_name, is_video, 'Number of followers does not reach minimum'\n\n    print('Link: {}'.format(link.encode('utf-8')))\n    print('Description: {}'.format(image_text.encode('utf-8')))\n\n    \"\"\"Check if the user_name is in the ignore_users list\"\"\"\n    if (user_name in ignore_users) or (user_name == username):\n        return True, user_name, is_video, 'Username'\n\n    if any((word in image_text for word in ignore_if_contains)):\n        return False, user_name, is_video, 'None'\n\n    dont_like_regex = []\n\n    for dont_likes in dont_like:\n        if dont_likes.startswith(\"#\"):\n            dont_like_regex.append(dont_likes + \"([^\\d\\w]|$)\")\n        elif dont_likes.startswith(\"[\"):\n            dont_like_regex.append(\"#\" + dont_likes[1:] + \"[\\d\\w]+([^\\d\\w]|$)\")\n        elif dont_likes.startswith(\"]\"):\n            dont_like_regex.append(\"#[\\d\\w]+\" + dont_likes[1:] + \"([^\\d\\w]|$)\")\n        else:\n            dont_like_regex.append(\"#[\\d\\w]*\" + dont_likes + \"[\\d\\w]*([^\\d\\w]|$)\")\n\n    for dont_likes_regex in dont_like_regex:\n        if re.search(dont_likes_regex, image_text, re.IGNORECASE):\n            return True, user_name, is_video, 'Inappropriate'\n\n    return False, user_name, is_video, 'None'\n\n\ndef like_image(browser):\n    \"\"\"Likes the browser opened image\"\"\"\n    like_elem = browser.find_elements_by_xpath(\"//a[@role = 'button']/span[text()='Like']\")\n    liked_elem = browser.find_elements_by_xpath(\"//a[@role = 'button']/span[text()='Unlike']\")\n\n    if len(like_elem) == 1:\n        browser.execute_script(\n            \"document.getElementsByClassName('\" + like_elem[0].get_attribute(\"class\") + \"')[0].click()\")\n        print('--> Image Liked!')\n        sleep(2)\n        return True\n    elif len(liked_elem) == 1:\n        print('--> Already Liked!')\n        return False\n    else:\n        print('--> Invalid Like Element!')\n        return False\n\n\ndef get_tags(browser, url):\n    \"\"\"Gets all the tags of the given description in the url\"\"\"\n    browser.get(url)\n    sleep(1)\n\n    graphql = browser.execute_script(\"return ('graphql' in window._sharedData.entry_data.PostPage[0])\")\n    if graphql:\n        image_text = browser.execute_script(\n            \"return window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.edge_media_to_caption.edges[0].node.text\")\n    else:\n        image_text = browser.execute_script(\"return window._sharedData.entry_data.PostPage[0].media.caption.text\")\n\n    tags = findall(r'#\\w*', image_text)\n    return tags\n", "path": "instapy/like_util.py"}], "after_files": [{"content": "import re\n\n\"\"\"Module that handles the like features\"\"\"\nfrom math import ceil\nfrom re import findall\nfrom selenium.webdriver.common.keys import Keys\n\nfrom .time_util import sleep\n\n\ndef get_links_for_location(browser, location, amount, media=None):\n    \"\"\"Fetches the number of links specified\n    by amount and returns a list of links\"\"\"\n    if media is None:\n        # All known media types\n        media = ['', 'Post', 'Video']\n    elif media == 'Photo':\n        # Include posts with multiple images in it\n        media = ['', 'Post']\n    else:\n        # Make it an array to use it in the following part\n        media = [media]\n\n    browser.get('https://www.instagram.com/explore/locations/'\n                + location)\n    sleep(2)\n\n    # clicking load more\n    body_elem = browser.find_element_by_tag_name('body')\n    sleep(2)\n\n    abort = True\n    try:\n        load_button = body_elem.find_element_by_xpath \\\n            ('//a[contains(@class, \"_1cr2e _epyes\")]')\n    except:\n        print('Load button not found, working with current images!')\n    else:\n        abort = False\n        body_elem.send_keys(Keys.END)\n        sleep(2)\n        load_button.click()\n\n    body_elem.send_keys(Keys.HOME)\n    sleep(1)\n\n    # Get links\n    main_elem = browser.find_element_by_tag_name('main')\n    link_elems = main_elem.find_elements_by_tag_name('a')\n    total_links = len(link_elems)\n    links = [link_elem.get_attribute('href') for link_elem in link_elems\n             if link_elem.text in media]\n    filtered_links = len(links)\n\n    while (filtered_links < amount) and not abort:\n        amount_left = amount - filtered_links\n        # Average items of the right media per page loaded\n        new_per_page = ceil(12 * filtered_links / total_links)\n        if new_per_page == 0:\n            # Avoid division by zero\n            new_per_page = 1. / 12.\n        # Number of page load needed\n        new_needed = int(ceil(amount_left / new_per_page))\n\n        if new_needed > 12:\n            # Don't go bananas trying to get all of instagram!\n            new_needed = 12\n\n        for i in range(new_needed):  # add images x * 12\n            # Keep the latest window active while loading more posts\n            before_load = total_links\n            body_elem.send_keys(Keys.END)\n            sleep(1)\n            body_elem.send_keys(Keys.HOME)\n            sleep(1)\n            link_elems = main_elem.find_elements_by_tag_name('a')\n            total_links = len(link_elems)\n            abort = (before_load == total_links)\n            if abort:\n                break\n\n        links = [link_elem.get_attribute('href') for link_elem in link_elems\n                 if link_elem.text in media]\n        filtered_links = len(links)\n\n    return links[:amount]\n\n\ndef get_links_for_tag(browser, tag, amount, media=None):\n    \"\"\"Fetches the number of links specified\n    by amount and returns a list of links\"\"\"\n    if media is None:\n        # All known media types\n        media = ['', 'Post', 'Video']\n    elif media == 'Photo':\n        # Include posts with multiple images in it\n        media = ['', 'Post']\n    else:\n        # Make it an array to use it in the following part\n        media = [media]\n\n    browser.get('https://www.instagram.com/explore/tags/'\n                + (tag[1:] if tag[:1] == '#' else tag))\n    sleep(2)\n\n    # clicking load more\n    body_elem = browser.find_element_by_tag_name('body')\n    sleep(2)\n\n    abort = True\n    try:\n        load_button = body_elem.find_element_by_xpath \\\n            ('//a[contains(@class, \"_1cr2e _epyes\")]')\n    except:\n        print('Load button not found, working with current images!')\n    else:\n        abort = False\n        body_elem.send_keys(Keys.END)\n        sleep(2)\n        load_button.click()\n\n    body_elem.send_keys(Keys.HOME)\n    sleep(1)\n\n    # Get links\n    main_elem = browser.find_element_by_tag_name('main')\n    link_elems = main_elem.find_elements_by_tag_name('a')\n    total_links = len(link_elems)\n    links = []\n    filtered_links = 0\n    try:\n        if link_elems:\n            links = [link_elem.get_attribute('href') for link_elem in link_elems\n                     if link_elem and link_elem.text in media]\n            filtered_links = len(links)\n\n    except BaseException as e:\n        print(\"link_elems error \\n\", str(e))\n\n    while (filtered_links < amount) and not abort:\n        amount_left = amount - filtered_links\n        # Average items of the right media per page loaded\n        new_per_page = ceil(12 * filtered_links / total_links)\n        if new_per_page == 0:\n            # Avoid division by zero\n            new_per_page = 1. / 12.\n        # Number of page load needed\n        new_needed = int(ceil(amount_left / new_per_page))\n\n        if new_needed > 12:\n            # Don't go bananas trying to get all of instagram!\n            new_needed = 12\n\n        for i in range(new_needed):  # add images x * 12\n            # Keep the latest window active while loading more posts\n            before_load = total_links\n            body_elem.send_keys(Keys.END)\n            sleep(1)\n            body_elem.send_keys(Keys.HOME)\n            sleep(1)\n            link_elems = main_elem.find_elements_by_tag_name('a')\n            total_links = len(link_elems)\n            abort = (before_load == total_links)\n            if abort:\n                break\n\n        links = [link_elem.get_attribute('href') for link_elem in link_elems\n                 if link_elem.text in media]\n        filtered_links = len(links)\n\n    return links[:amount]\n\n\ndef check_link(browser, link, dont_like, ignore_if_contains, ignore_users,\n               username, like_by_followers_upper_limit, like_by_followers_lower_limit):\n    browser.get(link)\n    sleep(2)\n\n    \"\"\"Check if the Post is Valid/Exists\"\"\"\n    post_page = browser.execute_script(\"return window._sharedData.entry_data.PostPage\")\n    if post_page is None:\n        print('Unavailable Page: {}'.format(link.encode('utf-8')))\n        return True, None, None, 'Unavailable Page'\n\n    \"\"\"Gets the description of the link and checks for the dont_like tags\"\"\"\n    graphql = 'graphql' in post_page[0]\n    if graphql:\n        media = post_page[0]['graphql']['shortcode_media']\n        is_video = media['is_video']\n        user_name = media['owner']['username']\n        image_text = media['edge_media_to_caption']['edges']\n        image_text = image_text[0]['node']['text'] if image_text else None\n        owner_comments = browser.execute_script('''\n      latest_comments = window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.edge_media_to_comment.edges;\n      if (latest_comments === undefined) latest_comments = Array();\n      owner_comments = latest_comments\n        .filter(item => item.node.owner.username == '{}')\n        .map(item => item.node.text)\n        .reduce((item, total) => item + '\\\\n' + total, '');\n      return owner_comments;\n    '''.format(user_name))\n    else:\n        media = post_page[0]['media']\n        is_video = media['is_video']\n        user_name = media['owner']['username']\n        image_text = media['caption']\n        owner_comments = browser.execute_script('''\n      latest_comments = window._sharedData.entry_data.PostPage[0].media.comments.nodes;\n      if (latest_comments === undefined) latest_comments = Array();\n      owner_comments = latest_comments\n        .filter(item => item.user.username == '{}')\n        .map(item => item.text)\n        .reduce((item, total) => item + '\\\\n' + total, '');\n      return owner_comments;\n    '''.format(user_name))\n\n    if owner_comments == '':\n        owner_comments = None\n\n    \"\"\"Append owner comments to description as it might contain further tags\"\"\"\n    if image_text is None:\n        image_text = owner_comments\n    elif owner_comments:\n        image_text = image_text + '\\n' + owner_comments\n\n    \"\"\"If the image still has no description gets the first comment\"\"\"\n    if image_text is None:\n        if graphql:\n            image_text = media['edge_media_to_comment']['edges']\n            image_text = image_text[0]['node']['text'] if image_text else None\n        else:\n            image_text = media['comments']['nodes']\n            image_text = image_text[0]['text'] if image_text else None\n    if image_text is None:\n        image_text = \"No description\"\n\n    print('Image from: {}'.format(user_name.encode('utf-8')))\n\n    \"\"\"Find the number of followes the user has\"\"\"\n    if like_by_followers_upper_limit or like_by_followers_lower_limit:\n        userlink = 'https://www.instagram.com/' + user_name\n        browser.get(userlink)\n        sleep(1)\n        num_followers = browser.execute_script(\n            \"return window._sharedData.entry_data.ProfilePage[0].user.followed_by.count\")\n        browser.get(link)\n        sleep(1)\n        print('Number of Followers: {}'.format(num_followers))\n\n        if like_by_followers_upper_limit and num_followers > like_by_followers_upper_limit:\n            return True, user_name, is_video, 'Number of followers exceeds limit'\n        if like_by_followers_lower_limit and num_followers < like_by_followers_lower_limit:\n            return True, user_name, is_video, 'Number of followers does not reach minimum'\n\n    print('Link: {}'.format(link.encode('utf-8')))\n    print('Description: {}'.format(image_text.encode('utf-8')))\n\n    \"\"\"Check if the user_name is in the ignore_users list\"\"\"\n    if (user_name in ignore_users) or (user_name == username):\n        return True, user_name, is_video, 'Username'\n\n    if any((word in image_text for word in ignore_if_contains)):\n        return False, user_name, is_video, 'None'\n\n    dont_like_regex = []\n\n    for dont_likes in dont_like:\n        if dont_likes.startswith(\"#\"):\n            dont_like_regex.append(dont_likes + \"([^\\d\\w]|$)\")\n        elif dont_likes.startswith(\"[\"):\n            dont_like_regex.append(\"#\" + dont_likes[1:] + \"[\\d\\w]+([^\\d\\w]|$)\")\n        elif dont_likes.startswith(\"]\"):\n            dont_like_regex.append(\"#[\\d\\w]+\" + dont_likes[1:] + \"([^\\d\\w]|$)\")\n        else:\n            dont_like_regex.append(\"#[\\d\\w]*\" + dont_likes + \"[\\d\\w]*([^\\d\\w]|$)\")\n\n    for dont_likes_regex in dont_like_regex:\n        if re.search(dont_likes_regex, image_text, re.IGNORECASE):\n            return True, user_name, is_video, 'Inappropriate'\n\n    return False, user_name, is_video, 'None'\n\n\ndef like_image(browser):\n    \"\"\"Likes the browser opened image\"\"\"\n    like_elem = browser.find_elements_by_xpath(\"//a[@role = 'button']/span[text()='Like']\")\n    liked_elem = browser.find_elements_by_xpath(\"//a[@role = 'button']/span[text()='Unlike']\")\n\n    if len(like_elem) == 1:\n        browser.execute_script(\n            \"document.getElementsByClassName('\" + like_elem[0].get_attribute(\"class\") + \"')[0].click()\")\n        print('--> Image Liked!')\n        sleep(2)\n        return True\n    elif len(liked_elem) == 1:\n        print('--> Already Liked!')\n        return False\n    else:\n        print('--> Invalid Like Element!')\n        return False\n\n\ndef get_tags(browser, url):\n    \"\"\"Gets all the tags of the given description in the url\"\"\"\n    browser.get(url)\n    sleep(1)\n\n    graphql = browser.execute_script(\"return ('graphql' in window._sharedData.entry_data.PostPage[0])\")\n    if graphql:\n        image_text = browser.execute_script(\n            \"return window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.edge_media_to_caption.edges[0].node.text\")\n    else:\n        image_text = browser.execute_script(\"return window._sharedData.entry_data.PostPage[0].media.caption.text\")\n\n    tags = findall(r'#\\w*', image_text)\n    return tags\n", "path": "instapy/like_util.py"}]}