Commit b4298bf5 by Luciano Barletta

first step towards clean input (attempt) reading

1 parent e2322e76
#-*- coding: utf-8 -*-
from flask import Flask, render_template, request, url_for
#from getDatos.py import SeleniumGet as SG
from iselenium.py import SeleniumInterface as SI
import random
app = Flask(__name__)
......@@ -75,12 +76,93 @@ data = {
@app.route('/')
def main():
#SG().getdata()
plate = "SLV350"
s = SI(SI.Chrome)
login(s)
gototec(s)
return render_template(
"resultados.html",
data = data
data = readdata(s)
)
def login(s):
s.get("https://rto.cent.gov.ar/rto")
login = s.find(SI.By.NAME, "j_username")
s.write(login, "salvatellih")
psw = s.find(SI.By.NAME, "j_password")
s.write(psw, "3")
button = s.find(SI.By.ID, "submit")
button.click()
def gototec(s):
s.get("https://rto.cent.gov.ar/rto/RTO/listaDePlanillas")
# children of parent of td with innerText = plate
columns = s.children(s.parent( s.find(SI.By.XPATH, f"//tr//td[text()='{plate}']") ))
# fecha
# get all a tags and click the last one
options = s.findFromElement(columns[-1], SI.By.TAG_NAME, "a", "1-")
options[-1].click()
# if last clickable is 'Datos Técnicos', click, else you are already there
tec = s.find(SI.By.XPATH, "//a/span[@class='externo']/parent::*", "1-")[-1]
if tec.get_attribute("innerText") == "ir a Datos Técnicos":
tec.click()
def readdata(s):
answer = {
"header" : {},
"alineador" : {},
"suspension" : [],
"frenos" : [],
"trasero" : {},
"gaseshumos" : {},
}
# Tables
frenos = s.find(SI.By.XPATH, "//table[@class='tabla_ensayo']")
estacionamiento = s.find(SI.By.ID, "tablaFrenoEstacionario")
medidas = s.find(SI.By.TAG_NAME, "fieldset")
ejes = s.findFromElement(frenos, SI.By.XPATH, "/tbody//tr[@class='even' or @class='odd']", "1-4")
for e in ejes:
c = s.children(e); a = []
# make a map from numbers to string indices? 1 => PesoEstatico, ...
# useful for random generated values too
# for the 2nd, 3rd, 5th and 6th column, attempt to read the value
for column in [c[1], c[2], c[4], c[5]]:
# reach: gets the first input child and reads it
reach = lambda c, s: s.read(s.findFromElement(c,SI.By.TAG_NAME, "input"))
a.append(attempt_do(reach, column, s))
answer.append(a)
# eje delantero
# fuerza freno estacionamiento
# co
# hc
# opacidad log
return answer
# Executes the lambda with the arguments, with try except
def attempt_do(f, *args, **kwargs, default = ""):
try:
return f(*args, **kwargs)
except:
return default
# Inicio del servicio
if __name__ == "__main__":
app.run("0.0.0.0")
\ No newline at end of file
......@@ -54,6 +54,9 @@ class SeleniumInterface:
self.write(element, k, clear = False)
element.send_keys(keys)
def read(self, element):
return element.get_attribute("value")
def _resolve(self, selector, elements):
div, rev, answer = selector.split("-"), False, []
......@@ -113,41 +116,4 @@ class NotEditable(Exception):
self.plate = plate
def __str__(self):
return f"The plate '{self.plate}' is not editable"
if __name__ == "__main__":
plate = "OQY729"
s = SeleniumInterface(SeleniumInterface.Chrome)
### Login ###
s.get("https://rto.cent.gov.ar/rto")
login = s.find(SeleniumInterface.By.NAME, "j_username")
s.write(login, "salvatellih")
psw = s.find(SeleniumInterface.By.NAME, "j_password")
s.write(psw, "3")
button = s.find(SeleniumInterface.By.ID, "submit")
button.click()
### Login ###
### Get to Data ###
s.get("https://rto.cent.gov.ar/rto/RTO/listaDePlanillas")
# children of parent of td with innerText = plate
columns = s.children(s.parent( s.find(SeleniumInterface.By.XPATH, f"//tr//td[text()='{plate}']") ))
# get all a tags and click the last one
options = s.findFromElement(columns[-1], SeleniumInterface.By.TAG_NAME, "a", "1-")
options[-1].click()
# get the 'Datos Técnicos' tag and click it
tec = s.find(SeleniumInterface.By.XPATH, "//a[text()='ir a Datos Técnicos']")
tec.click()
### Get to Data ###
### Read Data ###
### Read Data ###
\ No newline at end of file
return f"The plate '{self.plate}' is not editable"
\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!