-
Notifications
You must be signed in to change notification settings - Fork 2
/
excel_sheet.py
71 lines (54 loc) · 2.34 KB
/
excel_sheet.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import subprocess
import time
import openpyxl
ssid_required = ['Moto G (5S) Plus 3393', 'ZTE_5G_qaquFU', 'ZTE_2.4G_qaquFU']
def signalstrength():
signal_strength = []
# to turn on and off the wifi of system
subprocess.run(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', 'admin=disabled'])
subprocess.run(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', 'admin=enabled'])
time.sleep(5)
# getting the result of the command of command prompt and storing it in a variable
result = subprocess.check_output(["netsh", "wlan", "show", "network", "mode=Bssid"])
# converting the result(datatype = bytes) first into string object and storing each individual substring in a
# list cmd_output
cmd_output_list = list((result.decode('ASCII')).split())
# getting all the indexes of words SSID and Network and storing them in lists s1 and s2
i_SSID = [n for n, x in enumerate(cmd_output_list) if x == 'SSID']
i_Network = [n for n, x in enumerate(cmd_output_list) if x == 'Network']
i_Signal = [n for n, x in enumerate(cmd_output_list) if x == 'Signal']
# joining individual substrings to get one string for corresponding names of hotspots
for m in range(len(i_SSID)):
c = cmd_output_list[(i_SSID[m]+3):i_Network[m]]
c = tuple(c)
d = " "
if d.join(c) in ssid_required:
b = cmd_output_list[i_Signal[m] + 2]
b = b[0: len(b) - 1]
signal_strength.append((int(b))/2 - 100)
print(signal_strength)
return signal_strength
wb = openpyxl.load_workbook('x.xlsx')
sheet = wb['Sheet1']
sheet.cell(row=1, column=1).value = 'signal strength 1'
sheet.cell(row=1, column=2).value = 'signal strength 2'
sheet.cell(row=1, column=3).value = 'signal strength 3'
sheet.cell(row=1, column=4).value = 'x'
sheet.cell(row=1, column=5).value = 'y'
sheet.cell(row=1, column=6).value = 'z'
i = 2
while True:
a = input('You want to enter more values to database: y/n:- ')
if a == 'y':
signal_strengths = signalstrength()
s1 = signal_strengths[0]
s2 = signal_strengths[1]
s3 = signal_strengths[2]
sheet.cell(row=i, column=1).value = s1
sheet.cell(row=i, column=2).value = s2
sheet.cell(row=i, column=3).value = s3
i += 1
wb.save('x.xlsx')
elif a == 'n':
break
wb.save('x.xlsx')