Skip to content

Commit

Permalink
Added more functionality, including threading, and a useless way to c…
Browse files Browse the repository at this point in the history
…lose browser tabs.
  • Loading branch information
isaacholtis committed Feb 4, 2022
1 parent 686bcc8 commit d8fcc54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dep1Browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<body>

<p>This page opened to keep your browser window open while the bing bot completes it's searches.</p>
<p>This page opened to keep your browser window open while the bing bot completes it's searches. It can be safely closed once the searches have completed.</p>

</body>

Expand Down
24 changes: 16 additions & 8 deletions bingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
from random import randint
import pyautogui
import time
import threading

# Define webOpenSearch, which is used for threading so that multiple tabs can be opened at once.
def webOpenSearch(n, n2):
for i in range(n):
webbrowser.open(f"https://www.bing.com/search?q={randint(1,2000)}")
time.sleep(n2)
pyautogui.hotkey('ctrl', 'w')
# Get a variable to tell the system how many tabs to open.
searchNum = int(input("Please input the number of tabs you want to open.\nEach tab will open once, and then close, so feel free to do as many as you want!\n-->"))
# Get a variable to tell the system how long to wait before closing a tab.
# Note that I can't get the tabs to close well, with the system usually only closing one or two tabs.
timeNum = int(input("Please input how long you'd like to wait between searches.\nToo short of a time may cause the page to fail to load.\n-->"))

# We want to have searchNum = the number of tabs open in the browser, and we want to create a random number to update those tabs every 15 seconds, instead of opening a new tab and using too much ram.
for i in range(searchNum):
webbrowser.open(f"https://www.bing.com/search?q={randint(1,200)}")
time.sleep(timeNum)
pyautogui.hotkey('ctrl', 'w')
'''webbrowser.open("google.com")
# Opens a web page to keep the browser window open, for lighter resource usage, and faster operation.
webbrowser.open("Dep1Browser.html")
time.sleep(3)
pyautogui.hotkey('ctrl', 'w')
print("tab closed")'''
# Create a for loop that makes the threads needed to have multiple tabs open, using searchNum to detirmine how many there are.
for i in range(searchNum):
i = threading.Thread(target=webOpenSearch, args=(searchNum,timeNum))
i.start()

0 comments on commit d8fcc54

Please sign in to comment.