xaman123/fastapi-postgresql-code-audit-pro
0
1<!DOCTYPE html>2<html lang="en">3<head>4 <meta charset="UTF-8">5 <meta name="viewport" content="width=device-width, initial-scale=1.0">6 <title>GPS Emulator for Windows</title>7 <script src="https://cdn.tailwindcss.com"></script>8 <script src="https://unpkg.com/feather-icons"></script>9 <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>10 <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />11 <style>12 #map { height: 400px; }13 .coordinates {14 font-family: monospace;15 }16 </style>17</head>18<body class="bg-gray-100">19 <div class="container mx-auto px-4 py-8">20 <div class="text-center mb-8">21 <h1 class="text-3xl font-bold text-gray-800 mb-2">22 <i data-feather="map-pin" class="inline mr-2 text-blue-500"></i>23 GPS Emulator for Windows24 </h1>25 <p class="text-gray-600">Simulate GPS coordinates for testing web applications</p>26 </div>27 28 <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">29 <!-- Map Section -->30 <div class="lg:col-span-2 bg-white p-6 rounded-lg shadow">31 <div id="map" class="rounded-lg"></div>32 </div>33 34 <!-- Controls Section -->35 <div class="bg-white p-6 rounded-lg shadow">36 <h2 class="text-xl font-semibold mb-4 flex items-center">37 <i data-feather="settings" class="mr-2 text-blue-500"></i>38 Emulator Controls39 </h2>40 41 <div class="mb-6">42 <label class="block text-sm font-medium text-gray-700 mb-2">Current Position</label>43 <div class="bg-gray-100 p-3 rounded">44 <p class="coordinates">Latitude: <span id="latitude">0.0</span></p>45 <p class="coordinates">Longitude: <span id="longitude">0.0</span></p>46 </div>47 </div>48 49 <div class="mb-6">50 <label class="block text-sm font-medium text-gray-700 mb-2">Manual Coordinates</label>51 <div class="grid grid-cols-2 gap-3">52 <div>53 <input type="number" id="manual-lat" placeholder="Latitude" 54 class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" step="0.000001">55 </div>56 <div>57 <input type="number" id="manual-lng" placeholder="Longitude" 58 class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" step="0.000001">59 </div>60 </div>61 <button id="set-manual" class="mt-3 w-full bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded-md transition duration-300 flex items-center justify-center">62 <i data-feather="target" class="mr-2"></i>63 Set Position64 </button>65 </div>66 67 <div class="mb-6">68 <label class="block text-sm font-medium text-gray-700 mb-2">Movement Simulation</label>69 <select id="route-type" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 mb-3">70 <option value="random">Random Walk</option>71 <option value="circle">Circular Path</option>72 <option value="square">Square Path</option>73 <option value="line">Straight Line</option>74 </select>75 <div class="grid grid-cols-2 gap-3 mb-3">76 <div>77 <label class="block text-xs text-gray-500 mb-1">Speed (m/s)</label>78 <input type="number" id="speed" value="1" min="0.1" max="10" step="0.1"79 class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">80 </div>81 <div>82 <label class="block text-xs text-gray-500 mb-1">Interval (ms)</label>83 <input type="number" id="interval" value="1000" min="100" max="5000" step="100"84 class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">85 </div>86 </div>87 <button id="start-simulation" class="w-full bg-green-500 hover:bg-green-600 text-white py-2 px-4 rounded-md transition duration-300 flex items-center justify-center mb-2">88 <i data-feather="play" class="mr-2"></i>89 Start Simulation90 </button>91 <button id="stop-simulation" class="w-full bg-red-500 hover:bg-red-600 text-white py-2 px-4 rounded-md transition duration-300 flex items-center justify-center">92 <i data-feather="stop-circle" class="mr-2"></i>93 Stop Simulation94 </button>95 </div>96 97 <div>98 <label class="block text-sm font-medium text-gray-700 mb-2">Python WebSocket Server</label>99 <div class="bg-gray-100 p-3 rounded mb-3">100 <p class="text-xs font-mono">python -m gps_emulator.server</p>101 </div>102 <button id="copy-command" class="w-full bg-gray-500 hover:bg-gray-600 text-white py-2 px-4 rounded-md transition duration-300 flex items-center justify-center">103 <i data-feather="copy" class="mr-2"></i>104 Copy Command105 </button>106 </div>107 </div>108 </div>109 110 <!-- Python Code Section -->111 <div class="mt-8 bg-white p-6 rounded-lg shadow">112 <h2 class="text-xl font-semibold mb-4 flex items-center">113 <i data-feather="code" class="mr-2 text-blue-500"></i>114 Python Server Code115 </h2>116 <pre class="bg-gray-100 p-4 rounded-lg overflow-x-auto text-sm">117import asyncio118import websockets119import json120import random121from datetime import datetime122 123class GPSEmulator:124 def __init__(self):125 self.latitude = 0.0126 self.longitude = 0.0127 self.running = False128 self.simulation_task = None129 self.clients = set()130 131 async def update_position(self, lat, lng):132 self.latitude = lat133 self.longitude = lng134 await self.broadcast_position()135 136 async def broadcast_position(self):137 position = {138 "latitude": self.latitude,139 "longitude": self.longitude,140 "timestamp": datetime.now().isoformat()141 }142 message = json.dumps(position)143 if self.clients:144 await asyncio.wait([client.send(message) for client in self.clients])145 146 async def random_walk(self, speed=1, interval=1000):147 while self.running:148 # Random direction change149 lat_change = (random.random() - 0.5) * 0.0001 * speed150 lng_change = (random.random() - 0.5) * 0.0001 * speed151 152 self.latitude += lat_change153 self.longitude += lng_change154 155 await self.broadcast_position()156 await asyncio.sleep(interval / 1000)157 158 async def handle_connection(self, websocket, path):159 self.clients.add(websocket)160 try:161 async for message in websocket:162 data = json.loads(message)163 if data.get("type") == "set_position":164 await self.update_position(data["latitude"], data["longitude"])165 elif data.get("type") == "start_simulation":166 self.running = True167 asyncio.create_task(self.random_walk(168 speed=data.get("speed", 1),169 interval=data.get("interval", 1000)170 ))171 elif data.get("type") == "stop_simulation":172 self.running = False173 finally:174 self.clients.remove(websocket)175 176async def main():177 emulator = GPSEmulator()178 server = await websockets.serve(179 emulator.handle_connection, "localhost", 8765180 )181 print("GPS Emulator server running on ws://localhost:8765")182 await server.wait_closed()183 184if __name__ == "__main__":185 asyncio.run(main())186</pre>187 <div class="mt-4 flex justify-between">188 <button class="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded-md transition duration-300 flex items-center">189 <i data-feather="download" class="mr-2"></i>190 Download Python Script191 </button>192 <button class="bg-gray-500 hover:bg-gray-600 text-white py-2 px-4 rounded-md transition duration-300 flex items-center">193 <i data-feather="copy" class="mr-2"></i>194 Copy Full Code195 </button>196 </div>197 </div>198 </div>199 200 <script>201 feather.replace();202 203 // Initialize map204 const map = L.map('map').setView([51.505, -0.09], 13);205 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {206 attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'207 }).addTo(map);208 209 // Add marker210 const marker = L.marker([51.505, -0.09]).addTo(map);211 212 // Update position from manual input213 document.getElementById('set-manual').addEventListener('click', () => {214 const lat = parseFloat(document.getElementById('manual-lat').value) || 0;215 const lng = parseFloat(document.getElementById('manual-lng').value) || 0;216 updatePosition(lat, lng);217 });218 219 function updatePosition(lat, lng) {220 document.getElementById('latitude').textContent = lat.toFixed(6);221 document.getElementById('longitude').textContent = lng.toFixed(6);222 marker.setLatLng([lat, lng]);223 map.setView([lat, lng], 13);224 225 // Here you would send the coordinates to Python via WebSocket226 console.log(`Position updated to: ${lat}, ${lng}`);227 }228 229 // Simulation controls230 let simulationInterval;231 document.getElementById('start-simulation').addEventListener('click', () => {232 const speed = parseFloat(document.getElementById('speed').value) || 1;233 const interval = parseInt(document.getElementById('interval').value) || 1000;234 const routeType = document.getElementById('route-type').value;235 236 // Clear any existing interval237 if (simulationInterval) clearInterval(simulationInterval);238 239 // Start new simulation240 let lat = 51.505;241 let lng = -0.09;242 let direction = 0;243 244 simulationInterval = setInterval(() => {245 if (routeType === 'random') {246 lat += (Math.random() - 0.5) * 0.001 * speed;247 lng += (Math.random() - 0.5) * 0.001 * speed;248 } else if (routeType === 'circle') {249 direction += 0.1;250 lat = 51.505 + Math.sin(direction) * 0.01 * speed;251 lng = -0.09 + Math.cos(direction) * 0.01 * speed;252 }253 254 updatePosition(lat, lng);255 }, interval);256 });257 258 document.getElementById('stop-simulation').addEventListener('click', () => {259 if (simulationInterval) clearInterval(simulationInterval);260 });261 262 // Copy commands263 document.getElementById('copy-command').addEventListener('click', () => {264 navigator.clipboard.writeText('python -m gps_emulator.server');265 alert('Command copied to clipboard!');266 });267 </script>268</body>269</html>