spline optimization experiments + fixes

This commit is contained in:
printfuck 2020-04-22 06:23:26 +02:00
parent 4cb94cdd81
commit 957a3174d8
2 changed files with 27 additions and 7 deletions

20
main.py
View File

@ -9,12 +9,13 @@ from threading import Timer, Lock
import selenium
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import lxml.etree as etree
from cssselect import HTMLTranslator, SelectorError
import requests as req
from io import StringIO
import math
from spline import gcv,bspline
#import web
DB_HOST = "127.0.0.1"
@ -118,14 +119,18 @@ def getContent(entryUrl, session_cookies, selector):
return a.tostring()
#p1 = (23.,23.)
def move_mouse(p1, p2, driver, time=1000, n=400, click=False):
def move_mouse(p1, p2, driver, time_=1000, n=400, click=False):
action = ActionChains(driver);
points = bspline(gcv(p1,p2,5), degree=3, n=n)
points = bspline(gcv(p1,p2,12), degree=5, n=n)
print(points)
for point in points:
action.move_to_element(point[0],point[1]);
if point[0] < 0 or point[1] < 0:
continue
print(point[0],point[1])
action.move_by_offset(int(point[0]),int(point[1]));
action.perform();
sleep(time/(1000*n))
time.sleep(time_/(1000*n))
if click:
action.click()
@ -135,11 +140,14 @@ def get_loc(e):
def getSession(user, password, url="https://accounts.ft.com/login"):
#selenium
driver = selenium.webdriver.Chrome()
driver.set_window_position(0, 0)
driver.set_window_size(3840, 1920)
driver.get(url)
email = driver.find_element_by_id("enter-email")
pos1 = get_loc(email)
move_mouse((128.3, 345.2),pos1,driver, n=200)
print(pos1)
move_mouse((123.3, 334.2),pos1,driver, n=200)
email.send_keys(user)
time.sleep(2)

View File

@ -43,6 +43,18 @@ def bspline(cv, n=100, degree=3, periodic=False):
# Calculate result
return np.array(si.splev(u, (kv,cv.T,degree))).T
#a_d = dist.euclidean(cv[0],v[0])
#b_d = dist.euclidean(v[-1],cv[-1])
#a = np.array(list(zip(
# np.linspace(cv[0][0],v[0][0],a_d*2),
# np.linspace(cv[0][1],v[0][1],a_d*2))))
#b = np.array(list(zip(
# np.linspace(v[-1][0],cv[-1][0],b_d*2),
# np.linspace(v[-1][1],cv[-1][1],b_d*2))))
#return np.concatenate(a,v,b)
def gcv(p1,p2, n):
d = distance.euclidean(p1,p2)
@ -53,5 +65,5 @@ def gcv(p1,p2, n):
r_ = np.random.random_sample((n-2,))
s = np.array(list(zip(x_lst + d *(r_-0.5),y_lst + d *(r-0.5))))
b = np.concatenate((np.array([[p1[0],p1[1]]]),np.concatenate((s,np.array([[p2[0],p2[1]]])))))
return s
return b