A Python-based project to fetch paginated data from a WebSocket endpoint and relay each item to a webhook. This project is ideal for real-time data processing and integration tasks.
- WebSocket Integration: Connects to a WebSocket server to fetch data.
- Pagination Support: Automatically handles paginated responses.
- Webhook Relay: Sends each data item as a POST request to a configured webhook.
- Asynchronous Execution: Utilizes Python's
asyncioandaiohttpfor efficient operations. - Dynamic Headers: Supports custom HTTP headers for webhook requests.
- Docker (recommended)
- Alternatively: Python 3.8+ with required libraries (
websockets,aiohttp)
-
Clone the repository:
git clone https://github.com/your-username/websocket-to-webhook.git cd websocket-to-webhook -
Build the Docker image:
docker build -t websocket-to-webhook . -
Run the Docker container:
docker run -d --name websocket-webhook-relay websocket-to-webhook
-
Clone the repository:
git clone https://github.com/your-username/websocket-to-webhook.git cd websocket-to-webhook -
Install dependencies:
pip install -r requirements.txt
-
Run the script:
python main.py
- WebSocket URL: Replace the
WEBSOCKET_URLvalue in the script with your WebSocket endpoint. - Webhook URL: Replace the
WEBHOOK_URLvalue in the script with your POST endpoint. - Headers: Add or modify custom headers in the
HEADERSdictionary.
Example configuration in main.py:
WEBSOCKET_URL = "wss://your-websocket-url"
WEBHOOK_URL = "https://your-webhook-url"
HEADERS = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}- Make sure the
WEBSOCKET_URLandWEBHOOK_URLinmain.pyare configured. - Build and run the Docker container (see Installation steps above).
- Configure the URLs in
main.py. - Run the script:
python main.py
- Connects to the WebSocket endpoint.
- Sends a request with pagination (
cmd,page). - Processes the
cachearray from the WebSocket response. - Sends each item in
cacheto the webhook. - Automatically fetches the next page until all data is processed.
Sent: 24E124707E239183, Status: 200
Sent: 24E124707E239184, Status: 200
Page 1/24, Items received: 100
Sent: 24E124707E239185, Status: 200
...
All pages processed.
If not using Docker, ensure the following dependencies are installed:
websockets==12.0aiohttp==3.8.4
Install them with:
pip install -r requirements.txtFeel free to fork this repository, submit issues, or make pull requests. Contributions are welcome!
This project is licensed under the MIT License. See the LICENSE file for details.