Load Stories, and watch it until there is no more stores to watch for the related element
(browser, elem, logger, action_type, simulate=False)
| 187 | |
| 188 | |
| 189 | def watch_story(browser, elem, logger, action_type, simulate=False): |
| 190 | """ |
| 191 | Load Stories, and watch it until there is no more stores |
| 192 | to watch for the related element |
| 193 | """ |
| 194 | |
| 195 | # make sure we work with a lower case elem |
| 196 | elem = elem.lower() |
| 197 | |
| 198 | if action_type == "tag": |
| 199 | story_link = "https://www.instagram.com/explore/tags/{}".format(elem) |
| 200 | |
| 201 | else: |
| 202 | story_link = "https://www.instagram.com/{}".format(elem) |
| 203 | |
| 204 | web_address_navigator(browser, story_link) |
| 205 | # wait for the page to load |
| 206 | time.sleep(randint(2, 6)) |
| 207 | # order is important here otherwise we are not on the page of the story we want to watch |
| 208 | story_data = get_story_data(browser, elem, action_type, logger, simulate) |
| 209 | |
| 210 | if story_data["status"] == "not ok": |
| 211 | raise NoSuchElementException |
| 212 | |
| 213 | if story_data["reels_cnt"] == 0: |
| 214 | # nothing to watch, there is no stories |
| 215 | logger.info( |
| 216 | "No stories to watch (either there is none) or we have already watched everything" |
| 217 | ) |
| 218 | return 0 |
| 219 | |
| 220 | logger.info( |
| 221 | "Watched {} reels from {}: {}".format( |
| 222 | story_data["reels_cnt"], action_type, elem.encode("utf-8") |
| 223 | ) |
| 224 | ) |
| 225 | |
| 226 | # get the post-story delay time to sleep |
| 227 | naply = get_action_delay("story") |
| 228 | time.sleep(naply) |
| 229 | |
| 230 | return story_data["reels_cnt"] |
no test coverage detected