Automated Notepad File Management Script
This Python script automates the creation, handling, and content insertion of text files using a combination of Python's asyncio for asynchronous execution and automation tools like pyautogui. The script achieves the following key tasks:
- Creates a specified number of text files in a user-defined directory.
- Opens these files in Notepad.
- Fills each text file with data fetched from a web API (https://jsonplaceholder.typicode.com).
- Automates file management tasks such as opening directories, locating icons, and interacting with Notepad windows.
The script uses asynchronous methods for a more efficient workflow, making it suitable for automating large repetitive tasks with minimal human intervention.
- Directory Creation: Creates a directory on the desktop to store generated text files.
- Asynchronous API Requests: Retrieves data from an API endpoint asynchronously.
- Automated GUI Interaction: Uses
pyautoguito locate and interact with Notepad files. - Queue Management: Uses
asyncio.Queueto manage the flow of tasks such as adding files and posts.
To run this script, you'll need:
-
Python 3.7+: The script utilizes
asyncioandhttpx, which work best with newer Python versions. -
Required Packages: Install the following packages using
pip:pip install httpx aiofiles aioconsole pyautogui
-
Notepad Icon Image: Ensure you have an image of the Notepad icon (
notepad_icon.png) in the script's directory for locating the icons on the desktop.
-
Clone the Repository:
git clone <repository-url>
-
Navigate to the Project Directory:
cd <project-directory>
-
Install Dependencies:
pip install -r requirements.txt
To run the script:
python script.py- Enter the number of files: The script will prompt you to enter how many text files you want to create.
- Enter the directory name: Provide a directory name where the text files will be created (it will be located on your desktop).
- Directory & File Creation: The script will create a specified number of text files in the specified directory on your desktop.
- Data Fetching: The script will fetch data from a placeholder API to populate each text file.
- Automated Interaction: The script will open each file, write the fetched data, save it, and close it automatically.
- create_directory: Creates a directory on the desktop.
- fetch_json_from_url: Retrieves JSON data from a given URL.
- open_directory_in_explorer: Opens the specified directory in the system's file explorer.
- create_text_files: Creates empty text files.
- add_post_to_queue: Adds fetched data from API to a queue.
- locate_icon_positions: Uses
pyautoguito locate the position of text files on the desktop. - handle_notepad_interaction: Opens Notepad files and writes content fetched from the API.
- Icon Detection: If the desktop icons are in a non-standard view or too crowded, the icon location detection may not work correctly.
- Failsafe Mechanism:
pyautoguihas a failsafe mechanism (move the mouse to the top-left corner to stop the script). Make sure to keep this in mind while testing. - Windows OS: The script is designed to work with Notepad on Windows. It may require modifications for other platforms.
If you'd like to contribute:
- Fork the repository.
- Create a feature branch.
- Submit a pull request with a description of your changes.
This project is licensed under the MIT License. See the LICENSE file for more details.
- Your Name: Provide your contact information here.
- Placeholder API used: JSONPlaceholder.
- Thanks to PyAutoGUI for simplifying GUI automation in Python.