r/madeinpython • u/Agtechno101 • Oct 10 '22
I made a simple script that helps you stay focused while working
Essentially, the script closes a social media website that you might be distracted by whenever you open it. The script uses pyautogui to scan for the logo of the social media site because all social media sites have their logo at the top somewhere. When it detects that a logo is on the screen it uses the hotkey "ctrl" and "w" to close the tab. This is all done with pyautogui. Here's the script:
import time
import pyautogui
import requests
image_url = {"https://i.imgur.com/pl9mJJT.png": "youtube_dark.png",
"https://i.imgur.com/qv25l8p.png": "tiktok_light.png",
"https://i.imgur.com/uagowcj.png": "reddit_dark.png",
"https://i.imgur.com/TgW9j05.png": "twitter_dark.png",
"https://i.imgur.com/sbjWhlD.png": "youtube_light.png"}
# to add more sites here just put a link to the image, then choose a name for the file and add the
# file type at the end, examples are above of sites I already added
for key, value in image_url.items():
img_data = requests.get(key).content
with open(value, 'wb') as handler:
handler.write(img_data)
while True:
for key, value in image_url.items():
screenShot = pyautogui.locateCenterOnScreen(value, confidence=0.8)
print(screenShot)
if screenShot is not None:
pyautogui.hotkey("ctrl", "w")
break
time.sleep(5)I also made a youtube tutorial here (the script is much simpler in the video though): https://www.youtube.com/watch?v=y-TQZdd5898
here's the GitHub: https://github.com/MOOOKS/distractionStopper1000/tree/main
22
Upvotes
1
1
u/shortorbluff Oct 10 '22
Nice idea! Love the video!😃