Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Luciano Barletta
/
Pruebas-RTO
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit b4298bf5
authored
2020-01-20 15:20:38 +0000
by
Luciano Barletta
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
first step towards clean input (attempt) reading
1 parent
e2322e76
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
41 deletions
deploy.py
iselenium.py
deploy.py
View file @
b4298bf
#-*- coding: utf-8 -*-
#-*- coding: utf-8 -*-
from
flask
import
Flask
,
render_template
,
request
,
url_for
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__
)
app
=
Flask
(
__name__
)
...
@@ -75,12 +76,93 @@ data = {
...
@@ -75,12 +76,93 @@ data = {
@app.route
(
'/'
)
@app.route
(
'/'
)
def
main
():
def
main
():
#SG().getdata()
plate
=
"SLV350"
s
=
SI
(
SI
.
Chrome
)
login
(
s
)
gototec
(
s
)
return
render_template
(
return
render_template
(
"resultados.html"
,
"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
# Inicio del servicio
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
app
.
run
(
"0.0.0.0"
)
app
.
run
(
"0.0.0.0"
)
\ No newline at end of file
\ No newline at end of file
iselenium.py
View file @
b4298bf
...
@@ -54,6 +54,9 @@ class SeleniumInterface:
...
@@ -54,6 +54,9 @@ class SeleniumInterface:
self
.
write
(
element
,
k
,
clear
=
False
)
self
.
write
(
element
,
k
,
clear
=
False
)
element
.
send_keys
(
keys
)
element
.
send_keys
(
keys
)
def
read
(
self
,
element
):
return
element
.
get_attribute
(
"value"
)
def
_resolve
(
self
,
selector
,
elements
):
def
_resolve
(
self
,
selector
,
elements
):
div
,
rev
,
answer
=
selector
.
split
(
"-"
),
False
,
[]
div
,
rev
,
answer
=
selector
.
split
(
"-"
),
False
,
[]
...
@@ -113,41 +116,4 @@ class NotEditable(Exception):
...
@@ -113,41 +116,4 @@ class NotEditable(Exception):
self
.
plate
=
plate
self
.
plate
=
plate
def
__str__
(
self
):
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
\ No newline at end of file
return
f
"The plate '{self.plate}' is not editable"
\ No newline at end of file
\ No newline at end of file
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment