-
Notifications
You must be signed in to change notification settings - Fork 9
/
speedcheck.py
100 lines (81 loc) · 3.09 KB
/
speedcheck.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
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
from threading import Thread
from threading import RLock
from datetime import datetime
import json
import queue
import urllib.request
fileLock=RLock()
filename = 'results_'+datetime.now().strftime("%Y-%m-%d_%H.%M.%S")
f = open(filename,'w')
f.write("Street, City, State, Zip, emm_lat, emm_lng, emm_acc, Speed\n")
f.close()
e = open('bad_addresses','w')
e.close()
state = input('Enter your State (2 letter): ')
def test(street, city, zip, emm_stuff):
jsoncontent = {'Content-Type': 'application/json'}
try_again = True
while (try_again):
try:
url = "https://www.att.com/services/shop/model/ecom/shop/view/unified/qualification/service/CheckAvailabilityRESTService/invokeCheckAvailability"
postdata = json.dumps({
'userInputZip': zip,
'userInputAddressLine1': street,
'mode': 'fullAddress'}).encode(encoding='utf-8')
req = urllib.request.Request(url=url, data=postdata, headers=jsoncontent, method='POST')
resp = urllib.request.urlopen(req)
if resp.getcode() == 200:
speed = None
respobj = json.loads(resp.read().decode('utf-8'))
status = respobj['wbfcResponse']['statusName']
if status == 'Success':
speed = respobj['CkavDataBean']['maxHsiaSpeedAvailable']
if speed is None:
print('No service available at %s' % street)
elif speed.endswith(' Mbps'):
speed = speed[:-5]
else:
print('Availability check returned status %s' % status)
if speed is not None:
line = '%s, %s, %s, %s, %s, %s, %s, %s' % \
(street, city, state, zip, emm_stuff[0], emm_stuff[1], emm_stuff[2], speed)
print(line)
with fileLock:
f = open(filename,'a')
f.write(line + '\n')
f.close()
else:
print('Availability check returned HTTP status %d' % resp.getcode())
try_again=False
except Exception as x:
print(x)
try_again=False
with fileLock:
e = open('bad_addresses','a')
e.write(street+', '+city+', '+state+' '+emm_stuff[0]+', '+emm_stuff[1]+', '+emm_stuff[2]+', '+zip+'\n')
e.close()
def run_test(i):
i = i.strip()
if len(i.split(',')) < 4:
print('Input is incorrect for {}'.format(i))
return
street = i.split(',')[0]
city = i.split(',')[1]
zip = i.split(',')[2]
emm_stuff = i.split(',')[3:]
test(street, city, zip, emm_stuff)
def do_stuff(q):
while True:
run_test(q.get())
q.task_done()
q = queue.Queue(maxsize=0)
num_threads = 5
for i in range(num_threads):
worker = Thread(target=do_stuff, args=(q,))
worker.setDaemon(True)
worker.start()
houses = open('addresses','r')
for x in houses.readlines():
q.put(x)
houses.close()
q.join()