first commit: load yandex maps and simple random pilot
This commit is contained in:
61
main.py
Normal file
61
main.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import math
|
||||
import random
|
||||
from time import sleep
|
||||
|
||||
from selenium import webdriver
|
||||
import selenium
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_experimental_option("detach", True)
|
||||
driver = webdriver.Chrome(options)
|
||||
|
||||
driver.get("https://yandex.ru/maps/43/kazan/?ll=49.103814%2C55.794258&z=14")
|
||||
sleep(5)
|
||||
|
||||
html = driver.find_element(By.TAG_NAME, 'html')
|
||||
action = ActionChains(driver)
|
||||
|
||||
# Закрытие левой панели
|
||||
action.click(driver.find_element(By.CLASS_NAME, 'sidebar-toggle-button'))
|
||||
action.pause(0.2)
|
||||
action.move_to_element_with_offset(driver.find_element(By.XPATH, "//div[@class='rounded-controls']/div[@class='rounded-controls__child'][5]//button"), 5, 5)
|
||||
action.pause(0.2)
|
||||
action.perform()
|
||||
|
||||
# Режим спутника
|
||||
action.click(driver.find_element(By.CLASS_NAME, '_key_satellite'))
|
||||
action.pause(0.2)
|
||||
action.perform()
|
||||
|
||||
class RandomPilot():
|
||||
angle: float
|
||||
|
||||
def __init__(self):
|
||||
self.dangle = 0
|
||||
self.angle = random.random() * math.pi * 2
|
||||
self.velocity = 50
|
||||
|
||||
def step(self) -> tuple[float, float]:
|
||||
# Поворот угла траектории
|
||||
self.dangle += (random.random() - 0.5) * 0.1
|
||||
self.dangle = max(min(self.dangle, 0.2), -0.2)
|
||||
self.angle += self.dangle
|
||||
|
||||
dx = math.cos(self.angle) * self.velocity
|
||||
dy = math.sin(self.angle) * self.velocity
|
||||
|
||||
return dx, dy
|
||||
|
||||
randomPilot = RandomPilot()
|
||||
|
||||
while True:
|
||||
# Сдвиг камеры
|
||||
action = ActionChains(driver)
|
||||
action.move_to_element_with_offset(html, 200, 200)
|
||||
action.click_and_hold()
|
||||
action.move_by_offset(*randomPilot.step())
|
||||
action.release()
|
||||
action.perform()
|
||||
sleep(0.5)
|
||||
Reference in New Issue
Block a user