From bcb605126951c4178f3b8a70515c660963aabe23 Mon Sep 17 00:00:00 2001 From: target-drone Date: Thu, 28 Jun 2018 10:45:01 +0100 Subject: [PATCH 1/2] Update flights.py to run with python2 and python3 urllib2 is depreciated in python3. Small edit to detect the calling version and import the relevant module. --- build/portal/python/flights.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build/portal/python/flights.py b/build/portal/python/flights.py index d6a7137..acc5fbd 100644 --- a/build/portal/python/flights.py +++ b/build/portal/python/flights.py @@ -39,7 +39,13 @@ import datetime import json import time import os -import urllib2 +#urllib2 is depreciated in python3 +try: + # For Python 3.0 and later + from urllib.request import urlopen +except ImportError: + # Fall back to Python 2's urllib2 + from urllib2 import urlopen def log(string): #print(string) # uncomment to enable debug logging @@ -190,10 +196,10 @@ if __name__ == "__main__": #with open('/run/dump1090-mutability/aircraft.json') as data_file: # data = json.load(data_file) - # Switch from physical file location to using urllib2 after the addition of the dump1090-fa option. + # Switch from physical file location to using urlopen after the addition of the dump1090-fa option. # dump1090-fa and dump1090-mutability store aircraft.json in difrent locations. # However Lighttpd is set up to serve this file using the same URL no matter which version is installed. - response = urllib2.urlopen('http://localhost/dump1090/data/aircraft.json') + response = urlopen('http://localhost/dump1090/data/aircraft.json') data = json.load(response) processor.processAircraftList(data["aircraft"]) From c60777626c15fdea190a5fe86cd33ff13e847eb1 Mon Sep 17 00:00:00 2001 From: target-drone Date: Tue, 3 Jul 2018 15:26:46 +0100 Subject: [PATCH 2/2] 'deprecated' :) --- build/portal/python/flights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/portal/python/flights.py b/build/portal/python/flights.py index acc5fbd..8e1e29e 100644 --- a/build/portal/python/flights.py +++ b/build/portal/python/flights.py @@ -39,7 +39,7 @@ import datetime import json import time import os -#urllib2 is depreciated in python3 +#urllib2 is deprecated in python3 try: # For Python 3.0 and later from urllib.request import urlopen