Skip to content

Instantly share code, notes, and snippets.

@akent
Last active May 18, 2023 08:20
Show Gist options
  • Save akent/4663601 to your computer and use it in GitHub Desktop.
Save akent/4663601 to your computer and use it in GitHub Desktop.
Simple ATIS fetching with directly injected request.
#!/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())
@zachbf
Copy link

zachbf commented Jun 11, 2022

Hi Adam,

Sorry to drag this up once again, but i'm having a few issues getting this to run locally. I had ignorantly assumed i'd be able to get this running fairly quickly, but alas, not to be.

I'm wondering if it's the version of the suds client I'm using, etc. Out of interest, with the bot still working and pulling ATIS' for Twitter, are you able to tell me what suds package/version this is using? It may help me troubleshoot a little more. The suds client v1.1.1 documentation is providing me little assistance.

Cheers.

@akent
Copy link
Author

akent commented Jun 11, 2022

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:

httplib2==0.9
Pygments==1.5
suds==0.4
tweepy==2.0

@zachbf
Copy link

zachbf commented Jun 12, 2022

That did it, thanks @akent - working well now.

Cheers.

@zachbf
Copy link

zachbf commented May 18, 2023

Once again, sorry to dig up an old gist.

Here's a snippet running on python3 now. :)

https://gist.github.com/zachbf/6866a6a719e71af81a9d9685750f90e3

@akent
Copy link
Author

akent commented May 18, 2023

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