Skip to content

Instantly share code, notes, and snippets.

@akent
Last active May 18, 2023 08:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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())
@bkee06
Copy link

bkee06 commented Jul 4, 2021

Hi Adam,

Sorry for digging up such an old gist.

I was wondering several things:

  1. does this code still work for you?
  2. have you updated it?
  3. have you done or would you know how to do similar with zeep?

I am trying to create something similar to loop and provide a constantly updating ATIS, TAF in our aero club flight planning room.

Cheers,

@akent
Copy link
Author

akent commented Jul 4, 2021

@bkee06 No problem! Although old, yes this is still broadly working. But, having just rechecked it, I think I have updated it slightly to be able to provide a user agent string, I have just posted a new version.

A few months ago I thought I'd try migrating to zeep too but hit issues. As it was an unfamiliar codebase I just filed an issue and moved on, haven't revisited it since.

Good luck!

@jason120au
Copy link

Hi Adam,

Thanks for providing the script however I did find a few issues just thought I'd report them to help others who maybe troubleshooting and experiencing the same issues. It appears that I was getting an error due to line 74 of the script I had to change it so it just returns result not result.content.

Also to note and this has nothing to do with the script, the NAIPS username needs to be in capitals otherwise you may get an error regarding the requestor not being valid which is used as part of the wsdl on line 56..

@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