deploy.py
3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#-*- coding: utf-8 -*-
from flask import Flask, render_template, request, url_for
from iselenium.py import SeleniumInterface as SI
import random
app = Flask(__name__)
data = {
"header" : {
"dominio" : "dom",
"fecha" : "15-01-2019",
},
"alineador" : {
"eje_delan" : "0.000"
},
"suspension" : [
{
"ren_izq" : "0.000",
"peso" : "0.000",
"ren_der" : "0.000",
},
{
"ren_izq" : "0.000",
"peso" : "0.000",
"ren_der" : "0.000",
}
],
"frenos" : [
{
"f_izq" : "0.000",
"res_izq" : "0.000",
"ov_izq" : "0.000",
"peso" : "0.000",
"f_der" : "0.000",
"res_der" : "0.000",
"ov_der" : "0.000",
},
{
"f_izq" : "0.000",
"res_izq" : "0.000",
"ov_izq" : "0.000",
"peso" : "0.000",
"f_der" : "0.000",
"res_der" : "0.000",
"ov_der" : "0.000",
},
{
"f_izq" : "0.000",
"res_izq" : "0.000",
"ov_izq" : "0.000",
"peso" : "0.000",
"f_der" : "0.000",
"res_der" : "0.000",
"ov_der" : "0.000",
},
{
"f_izq" : "0.000",
"res_izq" : "0.000",
"ov_izq" : "0.000",
"peso" : "0.000",
"f_der" : "0.000",
"res_der" : "0.000",
"ov_der" : "0.000",
}
],
"trasero" : {
"f_izq" : "0.000",
"f_der" : "0.000"
},
"gaseshumos" : {
"co" : "0.000",
"hc" : "0.000",
"med" : "0.000"
}
}
@app.route('/')
def main():
plate = "SLV350"
s = SI(SI.Chrome)
login(s)
gototec(s)
return render_template(
"resultados.html",
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")