Last active
May 18, 2023 08:20
-
-
Save akent/4663601 to your computer and use it in GitHub Desktop.
Simple ATIS fetching with directly injected request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim: set fileencoding=utf-8 : | |
import logging | |
from suds.client import Client, HttpAuthenticated | |
from suds.transport import Transport | |
NAIPS_LOGIN = 'yourloginhere' | |
NAIPS_PASS = 'yourpasshere' | |
USER_AGENT = 'simple atis example' | |
logging.basicConfig(level=logging.INFO) | |
class Httplib2Response: | |
pass | |
class Httplib2Transport(Transport): | |
def __init__(self, **kwargs): | |
Transport.__init__(self) | |
self.http = httplib2.Http() | |
def send(self, request): | |
url = request.url | |
message = request.message | |
headers = request.headers | |
headers['User-Agent'] = USER_AGENT | |
response = Httplib2Response() | |
response.headers, response.message = self.http.request(url, | |
"POST", body=message, headers=headers) | |
return response | |
def open(self, request): | |
response = Httplib2Response() | |
request.headers['User-Agent'] = USER_AGENT | |
response.headers, response.message = self.http.request(request.url, "GET", | |
body=request.message, headers=request.headers) | |
return StringIO.StringIO(response.message) | |
def get_data(): | |
endpoint = 'https://www.airservicesaustralia.com/naips/briefing-service?wsdl' | |
client = Client(endpoint) | |
message = '''<?xml version="1.0" encoding="UTF-8"?> | |
<SOAP-ENV:Envelope | |
xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" | |
xmlns:ns1="http://www.airservicesaustralia.com/naips/xsd" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> | |
<SOAP-ENV:Header/> | |
<ns0:Body> | |
<ns1:loc-brief-rqs password="{pw}" requestor="{login}" source="atis"> | |
<ns1:loc>YSSY</ns1:loc> | |
<ns1:loc>YBBN</ns1:loc> | |
<ns1:loc>YSCB</ns1:loc> | |
<ns1:loc>YMML</ns1:loc> | |
<ns1:loc>YPAD</ns1:loc> | |
<ns1:loc>YPPH</ns1:loc> | |
<ns1:loc>YBCS</ns1:loc> | |
<ns1:flags met="true"/> | |
</ns1:loc-brief-rqs> | |
</ns0:Body> | |
</SOAP-ENV:Envelope> | |
''' | |
srv = getattr(client, 'service') | |
met = getattr(srv, 'loc-brief') | |
xmlreq = message.format(login=NAIPS_LOGIN, pw=NAIPS_PASS) | |
result = met(__inject={'msg': xmlreq}) | |
return result.content | |
if __name__ == "__main__": | |
print(get_data()) |
That did it, thanks @akent - working well now.
Cheers.
Once again, sorry to dig up an old gist.
Here's a snippet running on python3 now. :)
https://gist.github.com/zachbf/6866a6a719e71af81a9d9685750f90e3
That's awesome @zachbf - so simple! Nice work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes I'm sorry @zachbf it's all very much out-of-date now -- but as it's just kept on working I've never revisited it!
Just checked the running env and it's this, on python 2.7.13: