-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeed.py
59 lines (47 loc) · 1.07 KB
/
Speed.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
44
45
46
47
48
49
50
51
52
53
54
import datetime
import os
import mysql.connector
mydb3 = mysql.connector.connect(
host="localhost",
user='yashaskm11',
password='4747',
database='test'
)
mycursor3 = mydb3.cursor(buffered=True)
def Speedmonkey():
output = os.popen('speedtest-cli')
i=0
while True:
line = output.readline()
i+=1
if line:
if i==7:
dl=line
elif i==9:
ul=line
else:
break
output.close()
dl = extract(dl)
ul = extract(ul)
timestamp = datetime.datetime.now()
pushspeed((ul, dl, timestamp))
#time.sleep(20)
def pushspeed(val):
sql="insert into speedmonk values (%s,%s,%s)"
mycursor3.execute(sql,val)
mydb3.commit()
def extract(st):
fl=''
num=['1','2','3','4','5','6','7','8','9','0','.']
for i in st:
if i in num:
if i=='.':
if not fl=='':
fl=fl+i
else:
fl=fl+i
return float(fl)
def SpeedProc(q):
while q.empty():
Speedmonkey()