This Python script automates file tracking and uploading to Google Drive using the Watchdog
library for file system events, PyDrive
for interacting with Google Drive, and OAuth 2.0 for authentication. The script monitors a specified directory for file changes (creation only) and automatically uploads new files to a Google Drive folder when the script is running.
- Python 3.x installed on your system
- A Google account with access to Google Drive
- OAuth 2.0 credentials (client ID and client secret) for Google Drive API
- Required Python packages and modules:
Watchdog
,PyDrive
,dotenv
- A stable Internet/Mobile Data connection
- Ensure the script remains running at all times for consistent file uploads. Pressing
CTRL + C
will terminate the script, and aTERMINATE_NOTIF
will be logged in the console. - Do not clear your browser's cookies while the script is either: running or has already generated the necessary credentials for the API to prevent unprecedented behaviors.
- Open Command Prompt. (Win + R -> type cmd -> Enter)
- Navigate to the directory of the script. (type "cd path\to\script\here")
- Once in the directory, run the following command:
python main.py
- A
WATCHER_TRIGGER_NOTIF
will be logged into the console if it has successfully started the script. - Troubleshooting: If any error/s occur, check the following:
- Python is installed: Run
python --version
(orpython3 --version
on Linux/macOS) to verify. - Environment variables are correctly set: Ensure the
.env
file is in place with valid credentials. - Images Folder is in the directory: Check if there is a
Screenshots
Folder. - Creds folder is in the directory: Verify that creds folder contain the ff files:
- client_secrets_XXXX.json (OAuth 2.0 Client Secret for Google API)
- credentials.json (OAuth 2.0 Tokens - Generated after first authentication)
- settings.yml (Application-specific settings - folder paths, Google Drive ID)
- Internet Connection: Verify that the device is connected to the internet.
Watchdog
- monitors the specified directory for changes and triggers events (file created, modified, deleted). Watchdog Documentation- Google Drive Authentication Setup
- When a file is created or modified, the script uses
PyDrive
to authenticate via OAuth 2.0 and upload the file to Google Drive. PyDrive Setup
Below is a flowchart of the file tracking and uploading process:
If you have encountered any bugs/error, kindly notify the following officers ASAP via any GDSC - Related Group Chats.
- John Octavio - Web Development Lead
- Jared Ramon Elizan - Tech Officer | Web Development
- Toby Javelona - Tech Officer | AI