def play_shepherd_tour(driver, tour_steps, msg_dur, name=None, interval=<NUM_LIT:0>):
instructions = "<STR_LIT>"<EOL>for tour_step in tour_steps[name]:<EOL><INDENT>instructions += tour_step<EOL><DEDENT>instructions += ("""<STR_LIT>""")<EOL>autoplay = False<EOL>if interval and interval > <NUM_LIT:0>:<EOL><INDENT>autoplay = True<EOL>interval = float(interval)<EOL>if interval < <NUM_LIT:0.5>:<EOL><INDENT>interval = <NUM_LIT:0.5><EOL><DEDENT><DEDENT>if not is_shepherd_activated(driver):<EOL><INDENT>activate_shepherd(driver)<EOL><DEDENT>if len(tour_steps[name]) > <NUM_LIT:1>:<EOL><INDENT>try:<EOL><INDENT>selector = re.search(<EOL>r"<STR_LIT>",<EOL>tour_steps[name][<NUM_LIT:1>]).group(<NUM_LIT:1>)<EOL>selector = selector.replace('<STR_LIT:\\>', '<STR_LIT>')<EOL>page_actions.wait_for_element_present(<EOL>driver, selector, by=By.CSS_SELECTOR,<EOL>timeout=settings.SMALL_TIMEOUT)<EOL><DEDENT>except Exception:<EOL><INDENT>js_utils.post_messenger_error_message(<EOL>driver, "<STR_LIT>" % selector,<EOL>msg_dur)<EOL>raise Exception(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % selector)<EOL><DEDENT><DEDENT>driver.execute_script(instructions)<EOL>tour_on = True<EOL>if autoplay:<EOL><INDENT>start_ms = time.time() * <NUM_LIT><EOL>stop_ms = start_ms + (interval * <NUM_LIT>)<EOL>latest_element = None<EOL>latest_text = None<EOL><DEDENT>while tour_on:<EOL><INDENT>try:<EOL><INDENT>time.sleep(<NUM_LIT>)<EOL>result = driver.execute_script(<EOL>"<STR_LIT>")<EOL><DEDENT>except Exception:<EOL><INDENT>tour_on = False<EOL>result = None<EOL><DEDENT>if result:<EOL><INDENT>tour_on = True<EOL>if autoplay:<EOL><INDENT>try:<EOL><INDENT>element = driver.execute_script(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>shep_text = driver.execute_script(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>except Exception:<EOL><INDENT>continue<EOL><DEDENT>if element != latest_element or shep_text != latest_text:<EOL><INDENT>latest_element = element<EOL>latest_text = shep_text<EOL>start_ms = time.time() * <NUM_LIT><EOL>stop_ms = start_ms + (interval * <NUM_LIT>)<EOL><DEDENT>now_ms = time.time() * <NUM_LIT><EOL>if now_ms >= stop_ms:<EOL><INDENT>if ((element == latest_element) and (<EOL>shep_text == latest_text)):<EOL><INDENT>driver.execute_script("<STR_LIT>")<EOL>try:<EOL><INDENT>latest_element = driver.execute_script(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>latest_text = driver.execute_script(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>start_ms = time.time() * <NUM_LIT><EOL>stop_ms = start_ms + (interval * <NUM_LIT>)<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT>continue<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>time.sleep(<NUM_LIT>)<EOL>selector = driver.execute_script(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>try:<EOL><INDENT>js_utils.wait_for_css_query_selector(<EOL>driver, selector, timeout=settings.SMALL_TIMEOUT)<EOL><DEDENT>except Exception:<EOL><INDENT>remove_script = (<EOL>"<STR_LIT>" % "<STR_LIT>")<EOL>driver.execute_script(remove_script)<EOL>js_utils.post_messenger_error_message(<EOL>driver, "<STR_LIT>" % selector,<EOL>msg_dur)<EOL>time.sleep(<NUM_LIT:0.1>)<EOL><DEDENT>driver.execute_script("<STR_LIT>")<EOL>if autoplay:<EOL><INDENT>start_ms = time.time() * <NUM_LIT><EOL>stop_ms = start_ms + (interval * <NUM_LIT>)<EOL><DEDENT>tour_on = True<EOL><DEDENT>except Exception:<EOL><INDENT>tour_on = False<EOL>time.sleep(<NUM_LIT:0.1>)<EOL><DEDENT><DEDENT><DEDENT>
Plays a Shepherd tour on the current website.