-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPinCodeChecker.py
More file actions
52 lines (46 loc) · 1.69 KB
/
PinCodeChecker.py
File metadata and controls
52 lines (46 loc) · 1.69 KB
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
import csv
import json
import sys
from six.moves.urllib.request import urlopen
from nap.url import Url
import requests
class JsonApi(Url):
def after_request(self, response):
if response.status_code != 200:
response.raise_for_status()
return response.json()
def outputWriter( pin, response ):
if(response is None):
print("Bad response for Pin: " + pin)
return;
#jArray = json.loads( response )
#if(jArray[0]['total'] == 0):
if(response[0]['total'] == 0):
print("No response for Pin: " + pin)
return;
with open('Addresses.csv', 'a') as csvfile:
try:
spamwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)
spamwriter.writerow([pin, response[1]['v'], response[1]['i'], response[1]['lat'], response[1]['lon']])
#spamwriter.writerow([pin, jArray[1]['v'], jArray[1]['i'], jArray[1]['lat'], jArray[1]['lon']])
csvfile.flush()
print("Added address for pin code : " + pin)
except:
print("Failure in pin: " + pin)
pass
def evaluatePin( pin ):
link = "http://www.streetdirectory.com/api/?mode=search&profile=sd_auto&country=sg&q=" + pin + "&output=json&v=1.0.1.798"
try:
api = JsonApi(link)
#response = urlopen(link)
response=api.get()
#content = response.read().decode("utf-8")
outputWriter( pin, response )
except:
print("URL Error for Pin: " + pin)
count = 10000
while (count < 84000):
evaluatePin(str(count).zfill(6))
#print ("The count is: " + str(count))
count = count + 1
print ("Done!")