-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwifi2.py
43 lines (36 loc) · 1.32 KB
/
wifi2.py
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
import time
import sys
import datetime
import os
import subprocess
import MySQLdb
db = MySQLdb.connect(
host = '192.168.1.151',
user = 'pi',
passwd = '10416232',
db = 'wifi',
port = 3306)
curs = db.cursor()
try:
while True:
output = subprocess.check_output("speedtest-cli")
result = {}
for row in output.split("\n"):
if ': ' in row:
key, value = row.split(': ')
result[key.strip(' .')] = value.strip()
raw_download = result['Download']
raw_upload = result['Upload']
download, unit = raw_download.split(" ")
upload, unit2 = raw_upload.split(" ")
print("Download: " + download + " mbps")
print("Upload: " + upload + " mbps")
print("-------------------------------")
add_wifi=("INSERT INTO wifirecord VALUES(%s,%s,%s,%s)")
curs.execute(add_wifi, (time.strftime("%Y/%m/%d"), time.strftime("%H:%M:%S"),download,upload))
db.commit()
time.sleep(10)
except KeyboardInterrupt:
print("\nAkeyboard interrupt has been noticed.")
except:
print("An error or exception has occurred.")