Removed obsolete & uneeded import
[ais.git] / bin / extras / planeplotter_coaa.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 from __future__ import division
5 import urllib2, StringIO, gzip, time, random
6 from urlgrabber.keepalive import HTTPHandler
7
8 from ais.ntools import read_cfg
9
10 #plane plotter doen't use keep alive
11 #keepalive_handler = HTTPHandler()
12 #opener = urllib2.build_opener(keepalive_handler)
13 #urllib2.install_opener(opener)
14
15 __config_filename__ = '/etc/ais/planeplotter'
16
17 request = urllib2.Request('http://www.coaa.co.uk/planeinfo9x1.php')
18 request.add_header('User-Agent', 'PlanePlotter')
19 #request.add_header('Accept-encoding', 'gzip, deflate')
20 request.add_header('Cache-Control', 'no-cache')
21
22
23 cfg = read_cfg(__config_filename__)
24 reg = cfg['reg']
25 extracode = cfg['extracode']
26 ser = cfg['ser']
27 mouset = random.randint(1,60)
28 tt = int(time.time())
29
30 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
31 httpdata = uo.read()
32 uo.close()
33 if uo.headers.get('Content-Encoding')=='gzip':
34     compressedstream = StringIO.StringIO(httpdata)
35     gzipper = gzip.GzipFile(fileobj=compressedstream)
36     httpdata = gzipper.read()
37 print httpdata
38
39 #time.sleep(10)
40 #keepalive_handler.close_all()