Skip to content

Commit

Permalink
Fixed Merge conflit in readme.md while merging FocusWindow with main.
Browse files Browse the repository at this point in the history
  • Loading branch information
StDensity committed Sep 11, 2023
2 parents 4b6313d + c7bf980 commit d1f2f6b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 24 deletions.
66 changes: 56 additions & 10 deletions GUI_v0.1.0.py → GUI_v0.2.0.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import tkinter as tk
from tkinter import messagebox
from tkinter import ttk
import pyautogui as auto
import time
import random
import os
import pygetwindow as gw

# Create the main application window
root = tk.Tk()
Expand All @@ -28,13 +30,32 @@ def start_search():
# Disable the Start button to prevent multiple clicks
start_button['state'] = 'disabled'

# Disable Browser Close Check box
browser_close_checkbox.config(state="disabled")

# Call the execute_search function
execute_search(total_searches, browser_open_delay, inspect_element_delay, search_delay)


# Function to close the application
def close_app():
root.destroy()
exit(0)

def close_browser():
# ctrl + shift + w closes the active browser window
auto.hotkey('ctrl', 'shift', 'w')

def show_alert(title, message):
messagebox.showinfo(title, message)


def check_focus(required_window_id):
active_window_list_2 = gw.getWindowsWithTitle(gw.getActiveWindow().title)
current_browser = active_window_list_2[0]._hWnd
if required_window_id != current_browser:
show_alert("Error", "Browser focus lost. Exit(0)")
exit(0)


# Default delay values
Expand Down Expand Up @@ -71,14 +92,19 @@ def close_app():

# Create and configure the Start button
start_button = ttk.Button(frame, text="Start Search", command=start_search)
start_button.grid(row=4, columnspan=2, pady=20)
start_button.grid(row=4, columnspan=2, pady=10)

# Create and configure the Close button
close_button = ttk.Button(frame, text="Close", command=close_app)
close_button.grid(row=5, columnspan=2, pady=10)

# Browser close check box.
browser_close_var = tk.IntVar()
browser_close_checkbox = ttk.Checkbutton(frame, text="Close browser on completion", variable=browser_close_var)
browser_close_checkbox.grid(row=6, columnspan=2, padx=10)

note_label = ttk.Label(frame, text="Note: The total number of searches will be halved for both PC and mobile searches.")
note_label.grid(row=6, columnspan=2, pady=10)
note_label.grid(row=7, columnspan=2, pady=10)


# Function to execute the search
Expand All @@ -96,6 +122,10 @@ def execute_search(total_searches, browser_open_delay, inspect_element_delay, se
# Pause the script execution for the specified browser open delay
time.sleep(browser_open_delay)

# Getting the ID of the active window.
active_window_list = gw.getWindowsWithTitle(gw.getActiveWindow().title)
required_window_id = active_window_list[0]._hWnd

# Define a list of prefixes to be used in generating questions
prefix = [
"What is", "Define", "Explain", "Meaning of",
Expand All @@ -115,21 +145,28 @@ def execute_search(total_searches, browser_open_delay, inspect_element_delay, se
"K-means", "FNN", "Transfer Learning", "AutoML",
"Hyperparameter Optimization", "Reinforcement Learning",
"Deep Learning", "Regression Analysis", "Clustering",
"Dimensionality Reduction", "Backpropagation", "Overfitting",
"Underfitting", "Cross-Validation", "Natural Language Generation",
"Dimensionality Reduction", "Backpropagation", "Over fitting",
"Under fitting", "Cross-Validation", "Natural Language Generation",
"Supervised Learning", "Unsupervised Learning", "Neural Network Architecture",
"Bias-Variance Tradeoff", "Feature Engineering", "Convolutional Neural Network",
"Recurrent Neural Network", "Random Forest", "Gradient Descent"
]

# To check whether the browser has lost focus or not.
check_focus(required_window_id)

# Opens Inspect Elements
auto.hotkey('ctrl', 'shift', 'i')
time.sleep(inspect_element_delay)
# To check whether the browser has lost focus or not.
check_focus(required_window_id)
# This is the bring back focus to the browser from inspect elements
auto.hotkey('alt')

# Loop to automate a series of actions
for i in range(0, total_searches):
# To check whether the browser has lost focus or not.
check_focus(required_window_id)
if i == total_searches // 2:
# Toggles device mode
auto.hotkey('ctrl', 'shift', 'i')
Expand All @@ -148,16 +185,25 @@ def execute_search(total_searches, browser_open_delay, inspect_element_delay, se
auto.press("enter") # Press the "enter" key
time.sleep(search_delay) # Pause for the specified search delay

# To go to the Rewards site.
auto.hotkey('ctrl', 'l')
auto.typewrite("https://rewards.bing.com/")
auto.press("enter")
# To check whether the browser has lost focus or not.
check_focus(required_window_id)
if browser_close_var:
close_browser()
else:
# To go to the Rewards site.
auto.hotkey('ctrl', 'l')
auto.typewrite("https://rewards.bing.com/")
auto.press("enter")

# Closes Inspect Elements
auto.hotkey('ctrl', 'shift', 'i')
# Closes Inspect Elements
auto.hotkey('ctrl', 'shift', 'i')

# Re-enable Start Button
start_button['state'] = 'enabled'

# Disable Browser Close Check box
browser_close_checkbox.config(state="enabled")


# Run the Tkinter main loop
root.mainloop()
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
A program to automate web searches for quick Microsoft Rewards completion. (Both PC and Mobile)


# Note
Before starting, make sure the delays correspond to the time it takes to perform specific actions on your PC. <Br> <Br>
![Resources/Image/Delay_ScreenShot.png](Resources/Image/Delay_ScreenShot.png) <Br> <Br>

# Important
⚠️ To ensure that this works, the browser window should be open in full screen. If it isn't in full screen, please maximize it. <Br>
⚠️ Your Edge browser should be located at the following path: "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe". <Br>
This path is the default for most PCs, so it should not be a problem. If it is not located there, you can edit the code accordingly. <Br>

## Note
If your pc takes time to respond or the network is slow you can always change the wait time accordingly. <Br>
⚠️ Don't use the PC while the program is running. <Br>
⚠️ You might have a difficult time stopping the program mid-way. Don't worry about it. It'll soon stop <Br>
⚠️ You can stop the program by changing the active window. <Br>
⚠️ This code is provided for educational purposes only. <Br>
It serves as a demonstration of automating repetitive tasks using Python and tkinter. <Br>
Please use this code responsibly and in accordance with applicable laws and guidelines. <Br>
The author and contributors are not responsible for any misuse of this code. <Br>
Feel free to modify and distribute it while adhering to the license terms. <Br> <Br>

### Thank you <3

Any improvements or bugs, let me know. <Br>
If you are new and don't know how to use it. let me know. <Br> <Br>
Good Day :)


You can see the releases from here: https://github.com/StDensity/Microsoft-Rewards-Automation/releases

# Thank you <3


Any improvements or bugs, let me know. <Br>
If you are new and don't know how to use it. let me know. <Br> <Br>
Good Day :)

Binary file added Resources/Image/Delay_ScreenShot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pyautogui
PyGetWindow

0 comments on commit d1f2f6b

Please sign in to comment.