From 881c0b5e2b1137d0042efff9bc466c2ccb9dfaca Mon Sep 17 00:00:00 2001 From: robotiste Date: Wed, 8 May 2019 17:29:14 +0530 Subject: [PATCH] added support for python3 --- README.md | 6 +++++- bzbrowser.py | 33 +++++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 404009e..cb94260 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ An interactive browser of waterfall snapshots in the Bolidozor repository +# Launguage + +Python3 + ## Dependencies * bzpost * pysdl2 - * pyfits + * astropy.io.fits * numpy diff --git a/bzbrowser.py b/bzbrowser.py index 165e91c..2fcf1a9 100644 --- a/bzbrowser.py +++ b/bzbrowser.py @@ -3,14 +3,14 @@ import sdl2.ext import multiprocessing.dummy as mpdummy import threading -import Queue +import queue import bzpost -import pyfits -import StringIO -import urllib2 +import astropy.io.fits as pyfits +import io +import urllib import numpy as np -from httplib import BadStatusLine +from http.client import BadStatusLine from sdl2 import * @@ -27,7 +27,7 @@ def __init__(self, source, sink): self.thread = threading.Thread(target=self.async) self.thread.daemon = True self.covered_range = None - self.cover_reqs = Queue.Queue() + self.cover_reqs = queue.Queue() self.thread.start() @@ -44,8 +44,8 @@ def _cover(self, a, b): for ss in self.source.get_snapshots(a, b): if b > ss.time >= a: self.sink(ss) - except BadStatusLine, e: - print "oh no, a BadStatusLine!", e # TODO + except BadStatusLine as e: + print( "oh no, a BadStatusLine!", e) # TODO self.source.close() self.source.connect() @@ -77,7 +77,7 @@ def main(): 430, 600, SDL_WINDOW_SHOWN) windowsurface = SDL_GetWindowSurface(window) - main_thread_queue = Queue.Queue() + main_thread_queue = queue.Queue() def run_on_main_thread(func): main_thread_queue.put(func) @@ -94,11 +94,11 @@ def run_on_main_thread(func): drawable_snapshots = [] def put_up_snapshot(snapshot): - print "downloading %s..." % snapshot.url + print( "downloading %s..." % snapshot.url) + x = urllib.request.urlopen(snapshot.url) - fits = pyfits.open(StringIO.StringIO(urllib2.urlopen(snapshot.url).read())) - - print "downloading %s... done" % snapshot.url + fits = pyfits.open(io.BytesIO(x.read())) + print( "downloading %s... done" % snapshot.url) imunit = None for unit in fits: @@ -113,9 +113,8 @@ def finish(): h, w = img.shape surface = SDL_CreateRGBSurfaceFrom(rgbimg.ctypes.data, w, h, 24, 3 * w, 0, 0, 0, 0) - drawable_snapshots.append({'time': snapshot.time, 'surface': surface, - 'imgdata': rgbimg}) + 'imgdata': rgbimg}) run_on_main_thread(finish) collection = SnapshotCollection(connector, @@ -162,6 +161,4 @@ def finish(): if __name__ == "__main__": - sys.exit(main()) - - + sys.exit(main()) \ No newline at end of file