Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

6 Commits

Repository files navigation

URL Auto Opener

This script allows you to open multiple URLs from a CSV file in a web browser, with the ability to:

✅ Set a delay between URLs.
✅ Skip to the next URL by pressing Enter.
✅ Stop the script at any time by pressing Esc.
✅ Automatically close each tab before opening the next URL.

Installation

  • Download the URL_Opener.exe file.
  • Place your CSV file in the same directory.
  • Double-click URL_Opener.exe to start.

CSV File Format

The CSV file should contain one URL per row, like this:

https://example.com
https://github.com
https://openai.com

You can download an example CSV file: URL_Example.csv

Controls

🎯 Enter → Skip to the next URL.
🛑 Esc → Stop the script.

How the Script Work

📦 Requirements to Run in Python

To run this script using Python, you need the following:

1️⃣ Install Python and pip

  • Python
    • Download it from python.org
    • Or install it directly from the Microsoft Store (search for "Python" in the Store)
  • pip (Comes pre-installed with Python, but you can update it with:
    python -m pip install --upgrade pip

2️⃣ Install Required Libraries

If you're running the script as a .py file instead of the .exe, install the following dependencies:

pip install keyboard
  • csv → Built-in Python module (no installation required).
  • webbrowser → Built-in Python module (no installation required).
  • time → Built-in Python module (no installation required).
  • threading → Built-in Python module (no installation required).
  • keyboard → Requires manual installation (pip install keyboard).
🔍 How the Script Works (Detailed Explanation)

The script is composed of multiple functions that work together to automate the process of opening URLs. Here’s a breakdown of each part:

1. Reading URLs from the CSV File

defget_urls(file_path):
urls= []
try:
withopen(file_path, newline='', encoding='utf-8') ascsvfile:
reader=csv.reader(csvfile)
forrowinreader:
ifrow: # Ensure the row is not emptyurls.append(row[0]) # Take the first column as the URLexceptFileNotFoundError:
print(f"Error: File {file_path} not found.")
exceptExceptionase:
print(f"Error reading the file: {e}")
returnurls
  • Reads the CSV file.
  • Extracts URLs from the first column.
  • Handles errors if the file is missing or unreadable.

2. Opening URLs and Handling User Inputs

defopen_urls(urls, seconds_per_url=None, skip_key="enter", stop_key="esc"):
stop_script=threading.Event() # Persistent event to stop the script
  • stop_script is an event that stops the entire script when Esc is pressed.

3. Detecting the Stop Key (Esc) in a Separate Thread

deflisten_for_stop():
keyboard.wait(stop_key)
stop_script.set()
stop_thread=threading.Thread(target=listen_for_stop, daemon=True)
stop_thread.start()
  • Runs a background thread that listens for the Esc key.
  • If Esc is pressed, stop_script.set() is triggered, stopping the script.

4. Iterating Through the URLs

forurlinurls:
ifstop_script.is_set():
print("\nThe script has been stopped.")
breakprint(f"Opening URL: {url}")
webbrowser.open(url)
  • Opens each URL in the browser.
  • Checks if Esc was pressed before opening a new URL.

5. Waiting for Enter or Time Delay

stop_waiting=threading.Event() # Controls waiting timedefwait_for_key():
whilenotkeyboard.is_pressed(skip_key) andnotstop_script.is_set():
time.sleep(0.1)
stop_waiting.set()
  • Waits until Enter is pressed or the set time expires.
ifseconds_per_url:
key_thread=threading.Thread(target=wait_for_key, daemon=True)
key_thread.start()
stop_waiting.wait(timeout=seconds_per_url)
key_thread.join(timeout=0.1)
else:
keyboard.wait(skip_key)
  • If a delay is set, the script waits before moving to the next URL.
  • If no delay is set, the script waits for Enter to be pressed.

6. Closing the Current Tab

ifstop_script.is_set():
print("\nThe script has been stopped.")
breakkeyboard.press_and_release('ctrl+w')
time.sleep(0.5)
  • Closes the current browser tab (Ctrl + W).
  • Waits for 0.5 seconds before opening the next URL.

7. User Interface and Setup

defexplain_controls():
print("\nWelcome to the URL Opener!")
print("This script will open URLs from a CSV file and allow you to navigate between them.")
print("\nControls:")
print("- Press 'Enter' to skip to the next URL manually.")
print("- The script can automatically move to the next URL after a set time, or you can skip manually.")
print("- Press 'Esc' at any time to stop the script.")
  • Displays instructions before starting.
defwait_for_start():
input("\nPress 'Enter' to start the process...")
  • Waits for the user to press Enter before starting.
defask_for_delay():
delay_choice=input("Do you want a delay between URLs? (yes/no): ").strip().lower()
ifdelay_choice=="yes":
seconds=int(input("How many seconds do you want to wait between URLs? "))
returnsecondsreturnNone
  • Asks the user if they want a delay between URLs.

8. Main Execution

file_path=input("Enter the name of the CSV file (with .csv extension): ")
explain_controls()
seconds_per_url=ask_for_delay()
wait_for_start()
urls=get_urls(file_path)
ifurls:
open_urls(urls, seconds_per_url, skip_key, stop_key)
else:
print("No valid URLs found in the file.")
  • Asks for the CSV file name.
  • Displays instructions.
  • Asks for the delay time.
  • Reads the URLs and starts the process.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

This script allows you to open multiple URLs from a CSV file in a web browser

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages