This project provides a reliable geolocation service that retrieves user location data through a browser-based approach and exposes it via a Unix domain socket interface. It combines Selenium WebDriver automation with socket-based IPC to deliver accurate geolocation information to local system components.
The service uses Chrome in headless mode to access the browser's Geolocation API, providing high-accuracy location data including latitude, longitude, and accuracy metrics. It implements intelligent caching to minimize resource usage while maintaining data freshness, and exposes a robust Unix socket interface with proper error handling and validation. The service is designed for integration with local system components that require reliable geolocation data.
.
├── controllers/
│ └── LocationController.py
├── services/
│ └── LocationService.py
├── template/
│ └── index.html
├── tests/
│ ├── __init__.py
│ └── test_location_service.py
├── main.py
└── requirements.txt
- Python 3.6 or higher
- Chrome browser installed
- Unix-like operating system (Linux/MacOS) for Unix socket support
- The following Python packages:
- selenium==4.30.0
- webdriver_manager==4.0.2
- Clone the repository:
git clone https://github.com/thisoverride/glcsvc
cd glcsvc
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Linux/MacOS
# or
.venv\Scripts\activate # On Windows
- Install dependencies:
pip install -r requirements.txt
- Start the geolocation service:
python main.py
-
The service will create a Unix socket at
/tmp/sme-glcsvc.sock
-
Connect to the service using a Unix socket client:
import socket
import json
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect('/tmp/sme-glcsvc.sock')
request = {
"source": "CTL_LOCAL_SYS",
"version": 1.0,
"request": {
"type": "GET_LOC"
}
}
client.send(json.dumps(request).encode('utf-8'))
response = client.recv(1024)
print(json.loads(response.decode('utf-8')))
Example response format:
{
"location": {
"timestamp": "2023-09-20T14:30:00.123456",
"geolocation": {
"latitude": 37.7749,
"longitude": -122.4194,
"accuracy": 10
}
}
}
Common issues and solutions:
-
Socket file already exists:
- Error:
RuntimeError: The socket file /tmp/sme-glcsvc.sock already exists
- Solution: Remove the existing socket file:
rm /tmp/sme-glcsvc.sock
- Error:
-
Chrome driver issues:
- Error:
WebDriver not initialized
- Solution: Ensure Chrome is installed and up to date:
# On Ubuntu/Debian sudo apt update && sudo apt install google-chrome-stable
- Error:
-
Permission issues:
- Error:
Permission denied: '/tmp/sme-glcsvc.sock'
- Solution: Check socket file permissions:
sudo chmod 777 /tmp/sme-glcsvc.sock
- Error:
The service uses a browser-based approach to access the Geolocation API, processes the data through Selenium WebDriver, and serves it via a Unix domain socket.
[Browser Geolocation API] -> [Selenium WebDriver] -> [LocationService]
| |
v v
[HTML Template] [Location Cache]
| |
| v
+-------------> [LocationController] <-----------+
|
v
[Unix Domain Socket]
|
v
[Client Applications]
Component interactions:
- LocationService initializes Chrome in headless mode with Selenium WebDriver
- HTML template accesses browser's Geolocation API
- LocationService caches location data for 10 seconds
- LocationController validates incoming socket requests
- Valid requests trigger location retrieval from LocationService
- Location data is returned to clients in JSON format
- Error responses include specific error types and messages