Just show stats, and fix Keyerror bug

This commit is contained in:
Pedro de Oliveira 2017-10-23 23:09:47 +01:00
parent a7a9b62caa
commit 027a46014a
1 changed files with 22 additions and 22 deletions

View File

@ -77,12 +77,12 @@ if __name__ == "__main__":
COOKIES = login()
while True:
START1 = datetime.now()
print(datetime.now(), "Request page")
#print(datetime.now(), "Request page")
REQ = page_cable_settings(COOKIES)
print(datetime.now(), "Got page")
#print(datetime.now(), "Got page")
START2 = datetime.now()
print(datetime.now(), "Started parsing")
#print(datetime.now(), "Started parsing")
UTS = (datetime.strptime(REQ.headers['Date'],
'%a, %d %b %Y %H:%M:%S %Z') + timedelta(hours=1)
).strftime('%Y-%m-%d %H:%M:%S')
@ -105,36 +105,36 @@ if __name__ == "__main__":
if MATCHES:
CHANNEL[FIELD] = MATCHES.group(3).replace(' dBmV', '').replace(' MHz', '')
UP.append(CHANNEL)
print(datetime.now(), "Ended parsing")
#print(datetime.now(), "Ended parsing")
START3 = datetime.now()
CNX = dbconnect()
CURSOR = CNX.cursor()
print(datetime.now(), "Connected to DB")
#print(datetime.now(), "Connected to DB")
for ITEM in DOWN:
#try:
try:
CURSOR.execute(INSERT, (UTS, 0,
ITEM['rx_id_val_dn'],
ITEM['freq_val_dn'],
ITEM['power_val_dn'],
ITEM['snr_val_dn']))
#except mysql.connector.IntegrityError as err:
# pass
except KeyError as err:
pass
for ITEM in UP:
#try:
try:
CURSOR.execute(INSERT, (UTS, 1,
ITEM['cannel_id_val_up'],
ITEM['freq_val_up'],
ITEM['power_val_up'], None))
#except mysql.connector.IntegrityError, KeyError as err:
# pass
except KeyError as err:
pass
CNX.commit()
CURSOR.close()
CNX.close()
print(datetime.now(), "DB connection closed")
#print(datetime.now(), "DB connection closed")
END = datetime.now()
DELTA1 = START2 - START1
@ -145,5 +145,5 @@ if __name__ == "__main__":
DELTA1.total_seconds() * 1000,
DELTA2.total_seconds() * 1000,
DELTA3.total_seconds() * 1000))
print(datetime.now(), "Sleeping\n")
#print(datetime.now(), "Sleeping\n")
time.sleep(30)