def getComic(self, id=None):
        result = xJson(id)

        if result is not None:
            self.title = result['title']
            self.img = result['img']
            self.alt = result['alt']
            self.num = result['num']

            try:
                local_img = sublime.cache_path() + os.path.sep + 'Xkcd' + \
                    os.path.sep + self.img.split('/')[-1]
                urllib.request.urlretrieve(self.img, local_img)

            except urllib.error.HTTPError as e:
                sublime.error_message(
                    'Xkcd: %s: HTTP error %s retrieving image' % (__name__, str(e.code)))
            except urllib.error.URLError as e:
                sublime.error_message(
                    'Xkcd: %s: URL error %s retrieving image' % (__name__, str(e.reason)))

            self.output = '[' + str(self.num) + '] ' + \
                self.title + '\n\n' + self.alt

            panel = self.window.create_output_panel('xkcd_meta')
            panel.run_command('erase_view')
            self.window.run_command(
                "show_panel", {"panel": "output.xkcd_meta"})
            self.window.get_output_panel('xkcd_meta').run_command(
                'append', {'characters': self.output})
            panel.settings().set("word_wrap", True)
            # print(int(self.window.active_view().viewport_extent()[0]-self.window.active_view().layout_extent()[0]))

            self.window.open_file(local_img, sublime.TRANSIENT)

            global xkcd_open
            xkcd_open.append(self.num)

            # HANDLE NAVIGATION (first/previous/next/last) HERE...
        else:
            sublime.error_message('Xkcd: Error reading API response')
Background loop.
dataset/ETHPy150Open eivind88/xkcd/xkcd.py/XkcdGetComicCommand.getComic