Added old coaa scripts to subversion
[ais.git] / bin / extras / planeplotter_coaa.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import urllib2, StringIO, gzip, time, random
5 from urlgrabber.keepalive import HTTPHandler
6
7 from ais.ntools import read_cfg
8
9 #plane plotter doen't use keep alive
10 #keepalive_handler = HTTPHandler()
11 #opener = urllib2.build_opener(keepalive_handler)
12 #urllib2.install_opener(opener)
13
14 __config_filename__ = '/etc/ais/planeplotter'
15
16 request = urllib2.Request('http://www.coaa.co.uk/planeinfo9x1.php')
17 request.add_header('User-Agent', 'PlanePlotter')
18 #request.add_header('Accept-encoding', 'gzip, deflate')
19 request.add_header('Cache-Control', 'no-cache')
20
21
22 cfg = read_cfg(__config_filename__)
23 reg = cfg['reg']
24 extracode = cfg['extracode']
25 ser = cfg['ser']
26 mouset = random.randint(1,60)
27 tt = int(time.time())
28
29 uo = urllib2.urlopen(request, 'Lines=0&Reg=%(reg)s&Extracode=%(extracode)s&Uponly=0&PosLess=0&Mouset=%(mouset)d&LatN=144.450356&LatS=-143.075878&LonE=+237.636617&LonW=-217.642360&Fwd=0&Ver=5.3.3.7&Tt=%(tt)d&Ser=%(ser)s' % locals()) # Sometimes add '&Des=A15CB0' for selected plane
30 httpdata = uo.read()
31 uo.close()
32 if uo.headers.get('Content-Encoding')=='gzip':
33     compressedstream = StringIO.StringIO(httpdata)
34     gzipper = gzip.GzipFile(fileobj=compressedstream)
35     httpdata = gzipper.read()
36 print httpdata
37
38 #time.sleep(10)
39 #keepalive_handler.close_all()