mirror of
https://github.com/User0332/rewards-farmer.git
synced 2026-09-16 01:31:36 +00:00
optimize search completion speed
This commit is contained in:
@@ -61,6 +61,9 @@ class ElementSelectionUtils:
|
|||||||
def get_bing_search_bar(self):
|
def get_bing_search_bar(self):
|
||||||
return self.driver.find_element(By.TAG_NAME, "textarea")
|
return self.driver.find_element(By.TAG_NAME, "textarea")
|
||||||
|
|
||||||
|
def get_clear_bing_search_query_button(self):
|
||||||
|
return self.driver.find_element(By.ID, "sw_clx")
|
||||||
|
|
||||||
def get_visual_search_button(self):
|
def get_visual_search_button(self):
|
||||||
return self.driver.find_element(By.CSS_SELECTOR, "#sb_form > div.camera.icon")
|
return self.driver.find_element(By.CSS_SELECTOR, "#sb_form > div.camera.icon")
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ keyboard = mimic_typing.KeyboardUtils(driver)
|
|||||||
|
|
||||||
rewards = rewards_tasks.RewardsTaskUtils(driver)
|
rewards = rewards_tasks.RewardsTaskUtils(driver)
|
||||||
|
|
||||||
rewards.complete_all_tasks()
|
rewards.complete_required_searches()
|
||||||
|
|
||||||
input("Press Enter to exit...")
|
input("Press Enter to exit...")
|
||||||
|
|
||||||
|
|||||||
+16
-5
@@ -218,6 +218,7 @@ def choose_target_in_element(x: int, y: int, height: int, width: int) -> Point:
|
|||||||
class MouseUtils:
|
class MouseUtils:
|
||||||
def __init__(self, driver: webdriver.Edge):
|
def __init__(self, driver: webdriver.Edge):
|
||||||
self.driver = driver
|
self.driver = driver
|
||||||
|
self.fallback_init_pos = (0, 0) # default fallback position if mouse position is not initialized
|
||||||
self.reinitialize()
|
self.reinitialize()
|
||||||
|
|
||||||
def reinitialize(self):
|
def reinitialize(self):
|
||||||
@@ -225,14 +226,16 @@ class MouseUtils:
|
|||||||
self.init_driver_with_cursor_visualization()
|
self.init_driver_with_cursor_visualization()
|
||||||
|
|
||||||
def init_driver_with_mouse_tracking(self):
|
def init_driver_with_mouse_tracking(self):
|
||||||
js_tracker = """
|
initial_pos = self.fallback_init_pos
|
||||||
window.cursorX = 0;
|
|
||||||
window.cursorY = 0;
|
js_tracker = f"""
|
||||||
document.addEventListener('mousemove', function(event) {
|
window.cursorX = {initial_pos[0]};
|
||||||
|
window.cursorY = {initial_pos[1]};
|
||||||
|
document.addEventListener('mousemove', function(event) {{
|
||||||
console.log('Mouse moved to: ' + event.clientX + ', ' + event.clientY);
|
console.log('Mouse moved to: ' + event.clientX + ', ' + event.clientY);
|
||||||
window.cursorX = event.clientX;
|
window.cursorX = event.clientX;
|
||||||
window.cursorY = event.clientY;
|
window.cursorY = event.clientY;
|
||||||
});
|
}});
|
||||||
"""
|
"""
|
||||||
self.driver.execute_script(js_tracker)
|
self.driver.execute_script(js_tracker)
|
||||||
|
|
||||||
@@ -265,6 +268,12 @@ class MouseUtils:
|
|||||||
x = self.driver.execute_script("return window.cursorX;")
|
x = self.driver.execute_script("return window.cursorX;")
|
||||||
y = self.driver.execute_script("return window.cursorY;")
|
y = self.driver.execute_script("return window.cursorY;")
|
||||||
|
|
||||||
|
if (x, y) == (None, None):
|
||||||
|
self.reinitialize()
|
||||||
|
return self.get_current_mouse_position()
|
||||||
|
|
||||||
|
self.fallback_init_pos = (x, y)
|
||||||
|
|
||||||
return (x, y)
|
return (x, y)
|
||||||
|
|
||||||
def move_mouse(self, move_time: float, path_function: Callable[[float], Point], visualize: bool=True):
|
def move_mouse(self, move_time: float, path_function: Callable[[float], Point], visualize: bool=True):
|
||||||
@@ -281,6 +290,8 @@ class MouseUtils:
|
|||||||
actions.pointer_action.move_to_location(point[0], point[1])
|
actions.pointer_action.move_to_location(point[0], point[1])
|
||||||
actions.perform()
|
actions.perform()
|
||||||
|
|
||||||
|
self.fallback_init_pos = point
|
||||||
|
|
||||||
if visualize: self.driver.execute_script(f"window.moveVisualCursor({point[0]}, {point[1]});")
|
if visualize: self.driver.execute_script(f"window.moveVisualCursor({point[0]}, {point[1]});")
|
||||||
|
|
||||||
def move_to_element(self, element: WebElement, visualize: bool=True):
|
def move_to_element(self, element: WebElement, visualize: bool=True):
|
||||||
|
|||||||
+16
-16
@@ -110,8 +110,6 @@ class RewardsTaskUtils:
|
|||||||
|
|
||||||
self.tab_utils.switch_to_other_tab()
|
self.tab_utils.switch_to_other_tab()
|
||||||
|
|
||||||
self.mouse.reinitialize()
|
|
||||||
|
|
||||||
self.wait_for_then_click(self.elements.get_visual_search_button)
|
self.wait_for_then_click(self.elements.get_visual_search_button)
|
||||||
|
|
||||||
file_input = self.wait_for_element(self.elements.get_visual_search_file_input)
|
file_input = self.wait_for_element(self.elements.get_visual_search_file_input)
|
||||||
@@ -123,8 +121,6 @@ class RewardsTaskUtils:
|
|||||||
self.tab_utils.switch_to_other_tab()
|
self.tab_utils.switch_to_other_tab()
|
||||||
self.tab_utils.close_all_other_tabs()
|
self.tab_utils.close_all_other_tabs()
|
||||||
|
|
||||||
self.mouse.reinitialize()
|
|
||||||
|
|
||||||
def complete_misc_cards(self):
|
def complete_misc_cards(self):
|
||||||
self.switch_to_earn_page()
|
self.switch_to_earn_page()
|
||||||
|
|
||||||
@@ -145,29 +141,33 @@ class RewardsTaskUtils:
|
|||||||
|
|
||||||
self.tab_utils.close_all_other_tabs()
|
self.tab_utils.close_all_other_tabs()
|
||||||
|
|
||||||
def complete_twenty_searches(self):
|
def complete_required_searches(self):
|
||||||
|
self.switch_to_earn_page()
|
||||||
|
self.wait_for_then_click(self.elements.get_points_breakdown_button)
|
||||||
|
self.wait_for_element(self.elements.get_close_button_on_points_breakdown) # make sure sidebar loads
|
||||||
|
|
||||||
|
points_earned, max_pts = self.elements.get_points_earned_from_searches_on_points_breakdown()
|
||||||
|
searches_needed = (max_pts - points_earned) // 5
|
||||||
|
|
||||||
self.driver.get("https://www.bing.com/")
|
self.driver.get("https://www.bing.com/")
|
||||||
|
|
||||||
search_bar = self.wait_for_element(self.elements.get_bing_search_bar)
|
self.wait_for_element(self.elements.get_bing_search_bar)
|
||||||
|
|
||||||
# search bar should be auto-focused
|
# search bar should be auto-focused
|
||||||
|
|
||||||
for query in llm_utils.get_related_search_queries(
|
for i, query in enumerate(
|
||||||
llm_utils.get_random_noun(), num_queries=20
|
llm_utils.get_related_search_queries(
|
||||||
|
llm_utils.get_random_noun(), num_queries=searches_needed
|
||||||
|
)
|
||||||
):
|
):
|
||||||
self.keyboard.send_keys(query+Keys.ENTER)
|
self.keyboard.send_keys(query+Keys.ENTER)
|
||||||
|
|
||||||
time.sleep(random.uniform(2, 3))
|
time.sleep(random.uniform(0.5, 1))
|
||||||
|
|
||||||
# clear search bar for next query
|
self.move_to_and_click(self.elements.get_clear_bing_search_query_button())
|
||||||
# the 't' can be any character, it just needs to be there to
|
|
||||||
# auto-focus the search bar so that the backspaces will work
|
|
||||||
self.keyboard.send_keys('t'+Keys.BACKSPACE*(len(query)+1))
|
|
||||||
|
|
||||||
self.driver.get("https://rewards.bing.com/")
|
self.driver.get("https://rewards.bing.com/")
|
||||||
|
|
||||||
self.mouse.reinitialize()
|
|
||||||
|
|
||||||
self.switch_to_earn_page()
|
self.switch_to_earn_page()
|
||||||
|
|
||||||
self.wait_for_then_click(self.elements.get_points_breakdown_button)
|
self.wait_for_then_click(self.elements.get_points_breakdown_button)
|
||||||
@@ -195,5 +195,5 @@ class RewardsTaskUtils:
|
|||||||
self.complete_explore_on_bing_tasks()
|
self.complete_explore_on_bing_tasks()
|
||||||
self.complete_visual_search()
|
self.complete_visual_search()
|
||||||
self.complete_misc_cards()
|
self.complete_misc_cards()
|
||||||
self.complete_twenty_searches()
|
self.complete_required_searches()
|
||||||
self.claim_bonus_points()
|
self.claim_bonus_points()
|
||||||
Reference in New Issue
Block a user