-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
28 lines (22 loc) · 1.46 KB
/
main.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
import requests
import html
import re
s = '''<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ProcessWebServiceRequest xmlns="http://edupoint.com/webservices/"><userID>EdupointDistrictInfo</userID><password>Edup01nt</password><skipLoginLog>1</skipLoginLog><parent>0</parent><webServiceHandleName>HDInfoServices</webServiceHandleName><methodName>GetMatchingDistrictList</methodName><paramStr><Parms><Key>5E4B7859-B805-474B-A833-FDB15D205D40</Key><MatchToDistrictZipCode>{0}</MatchToDistrictZipCode></Parms></paramStr></ProcessWebServiceRequest></soap:Body></soap:Envelope>'''
headers = {
'SOAPAction': 'http://edupoint.com/webservices/ProcessWebServiceRequest',
'Content-Type': 'text/xml; charset=utf-8'
}
def get_schools_by_zip_code(zip_code):
r = requests.post('https://support.edupoint.com/Service/HDInfoCommunication.asmx',
data=s.format(zip_code),
headers=headers)
districts = re.findall(r'<DistrictInfo (.+)/>', html.unescape(r.text))
return [
{
k: v for (k, v) in ((prop[0], prop[1])
for prop in re.findall(r'([A-Za-z]+)="([^"]*)"', district))
} for district in districts
]
if __name__ == '__main__':
print(get_schools_by_zip_code(94127))