def getandsend(self, event=None, retrying=False):

        if not retrying:
            if time() < self.holdofftime: return	# Was invoked by Return key while in cooldown
            self.cmdr['text'] = self.system['text'] = self.station['text'] = ''
            self.status['text'] = 'Fetching station data...'
            self.button['state'] = tk.DISABLED
            self.w.update_idletasks()

        try:
            querytime = int(time())

            data = self.session.query()

            self.cmdr['text'] = data.get('commander') and data.get('commander').get('name') or ''
            self.system['text'] = data.get('lastSystem') and data.get('lastSystem').get('name') or ''
            self.station['text'] = data.get('commander') and data.get('commander').get('docked') and data.get('lastStarport') and data.get('lastStarport').get('name') or '-'

            config.set('querytime', querytime)
            self.holdofftime = querytime + companion.holdoff

            # Validation
            if not data.get('commander') or not data['commander'].get('name','').strip():
                self.status['text'] = "Who are you?!"		# Shouldn't happen
            elif not data.get('lastSystem') or not data['lastSystem'].get('name','').strip() or not data.get('lastStarport') or not data['lastStarport'].get('name','').strip():
                self.status['text'] = "Where are you?!"		# Shouldn't happen
            elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name','').strip():
                self.status['text'] = "What are you flying?!"	# Shouldn't happen
            elif (config.getint('output') & config.OUT_EDDN) and not data['lastStarport'].get('ships') and not retrying:
                # API is flakey about shipyard info - retry if missing (<1s is usually sufficient - 2.5s for margin).
                self.w.after(2500, lambda:self.getandsend(retrying=True))
                return
            else:
                if __debug__ and retrying: print data['lastStarport'].get('ships') and 'Retry for shipyard - Success' or 'Retry for shipyard - Fail'

                # stuff we can do when not docked
                if __debug__:	# Recording
                    with open('%s%s.%s.json' % (data['lastSystem']['name'], data['commander'].get('docked') and '.'+data['lastStarport']['name'] or '', strftime('%Y-%m-%dT%H.%M.%S', localtime())), 'wt') as h:
                        h.write(json.dumps(data, indent=2, sort_keys=True))
                if config.getint('output') & config.OUT_LOG:
                    flightlog.export(data)
                if config.getint('output') & config.OUT_SHIP:
                    loadout.export(data)

                if not (config.getint('output') & (config.OUT_CSV|config.OUT_TD|config.OUT_BPC|config.OUT_EDDN)):
                    # no further output requested
                    self.status['text'] = strftime('Last updated at %H:%M:%S', localtime(querytime))

                elif not data['commander'].get('docked'):
                    self.status['text'] = "You're not docked at a station!"
                else:
                    if data['lastStarport'].get('commodities'):
                        # Fixup anomalies in the commodity data
                        self.session.fixup(data['lastStarport']['commodities'])

                        if config.getint('output') & config.OUT_CSV:
                            bpc.export(data, True)
                        if config.getint('output') & config.OUT_TD:
                            td.export(data)
                        if config.getint('output') & config.OUT_BPC:
                            bpc.export(data, False)

                    if config.getint('output') & config.OUT_EDDN:
                        if data['lastStarport'].get('commodities') or data['lastStarport'].get('modules') or data['lastStarport'].get('ships'):
                            self.status['text'] = 'Sending data to EDDN...'
                            self.w.update_idletasks()
                            eddn.export(data)
                            self.status['text'] = strftime('Last updated at %H:%M:%S', localtime(querytime))
                        else:
                            self.status['text'] = "Station doesn't have anything!"
                    elif not data['lastStarport'].get('commodities'):
                        self.status['text'] = "Station doesn't have a market!"
                    else:
                        self.status['text'] = strftime('Last updated at %H:%M:%S', localtime(querytime))

        except companion.VerificationRequired:
            return prefs.AuthenticationDialog(self.w, self.verify)

        # Companion API problem
        except companion.ServerError as e:
            self.status['text'] = str(e)

        except requests.exceptions.ConnectionError as e:
            if __debug__: print_exc()
            self.status['text'] = "Error: Can't connect to EDDN"

        except requests.exceptions.Timeout as e:
            if __debug__: print_exc()
            self.status['text'] = "Error: Connection to EDDN timed out"

        except Exception as e:
            if __debug__: print_exc()
            self.status['text'] = str(e)

        self.cooldown()
    def getandsend(self, event=None):
        if time() < self.holdofftime: return	# Was invoked by Return key while in cooldown

        self.cmdr['text'] = self.system['text'] = self.station['text'] = ''
        self.status['text'] = 'Fetching market data...'
        self.button['state'] = tk.DISABLED
        self.w.update_idletasks()

        try:
            querytime = int(time())

            data = self.session.query()

            self.cmdr['text'] = data.get('commander') and data.get('commander').get('name') or ''
            self.system['text'] = data.get('lastSystem') and data.get('lastSystem').get('name') or ''
            self.station['text'] = data.get('commander') and data.get('commander').get('docked') and data.get('lastStarport') and data.get('lastStarport').get('name') or '-'

            config.set('querytime', querytime)
            self.holdofftime = querytime + companion.holdoff

            # Validation
            if not data.get('commander') or not data['commander'].get('name','').strip():
                self.status['text'] = "Who are you?!"		# Shouldn't happen
            elif not data.get('lastSystem') or not data['lastSystem'].get('name','').strip() or not data.get('lastStarport') or not data['lastStarport'].get('name','').strip():
                self.status['text'] = "Where are you?!"		# Shouldn't happen
            elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name','').strip():
                self.status['text'] = "What are you flying?!"	# Shouldn't happen
            else:
                # stuff we can do when not docked
                if config.getint('output') & config.OUT_LOG:
                    flightlog.export(data)
                if config.getint('output') & config.OUT_SHIP:
                    loadout.export(data)

                if not (config.getint('output') & (config.OUT_CSV|config.OUT_TD|config.OUT_BPC|config.OUT_EDDN)):
                    # no further output requested
                    self.status['text'] = strftime('Last updated at %H:%M:%S', localtime(querytime))

                elif not data['commander'].get('docked'):
                    self.status['text'] = "You're not docked at a station!"
                elif not data['lastStarport'].get('commodities'):
                    self.status['text'] = "Station doesn't have a market!"
                else:
                    if config.getint('output') & config.OUT_CSV:
                        bpc.export(data, True)
                    if config.getint('output') & config.OUT_TD:
                        td.export(data)
                    if config.getint('output') & config.OUT_BPC:
                        bpc.export(data, False)
                    if config.getint('output') & config.OUT_EDDN:
                        self.status['text'] = 'Sending data to EDDN...'
                        self.w.update_idletasks()
                        eddn.export(data)
                    self.status['text'] = strftime('Last updated at %H:%M:%S', localtime(querytime))

        except companion.VerificationRequired:
            return prefs.AuthenticationDialog(self.w, self.verify)

        except companion.ServerError as e:
            self.status['text'] = str(e)

        except Exception as e:
            if __debug__: print_exc()
            self.status['text'] = str(e)

        self.cooldown()
    def getandsend(self, event=None, retrying=False):

        if not retrying:
            if time() < self.holdofftime:
                return  # Was invoked by Return key while in cooldown
            self.cmdr['text'] = self.system['text'] = self.station['text'] = ''
            self.status['text'] = 'Fetching station data...'
            self.button['state'] = tk.DISABLED
            self.w.update_idletasks()

        try:
            querytime = int(time())

            data = self.session.query()

            self.cmdr['text'] = data.get('commander') and data.get(
                'commander').get('name') or ''
            self.system['text'] = data.get('lastSystem') and data.get(
                'lastSystem').get('name') or ''
            self.station['text'] = data.get('commander') and data.get(
                'commander').get('docked') and data.get(
                    'lastStarport') and data.get('lastStarport').get(
                        'name') or '-'

            config.set('querytime', querytime)
            self.holdofftime = querytime + companion.holdoff

            # Validation
            if not data.get('commander') or not data['commander'].get(
                    'name', '').strip():
                self.status['text'] = "Who are you?!"  # Shouldn't happen
            elif not data.get('lastSystem') or not data['lastSystem'].get(
                    'name', '').strip() or not data.get(
                        'lastStarport') or not data['lastStarport'].get(
                            'name', '').strip():
                self.status['text'] = "Where are you?!"  # Shouldn't happen
            elif not data.get('ship') or not data['ship'].get(
                    'modules') or not data['ship'].get('name', '').strip():
                self.status[
                    'text'] = "What are you flying?!"  # Shouldn't happen
            elif (config.getint('output') & config.OUT_EDDN
                  ) and not data['lastStarport'].get('ships') and not retrying:
                # API is flakey about shipyard info - retry if missing (<1s is usually sufficient - 2.5s for margin).
                self.w.after(2500, lambda: self.getandsend(retrying=True))
                return
            else:
                if __debug__ and retrying:
                    print data['lastStarport'].get(
                        'ships'
                    ) and 'Retry for shipyard - Success' or 'Retry for shipyard - Fail'

                # stuff we can do when not docked
                if __debug__:  # Recording
                    with open(
                            '%s%s.%s.json' %
                        (data['lastSystem']['name'],
                         data['commander'].get('docked')
                         and '.' + data['lastStarport']['name'] or '',
                         strftime('%Y-%m-%dT%H.%M.%S', localtime())),
                            'wt') as h:
                        h.write(json.dumps(data, indent=2, sort_keys=True))
                if config.getint('output') & config.OUT_LOG:
                    flightlog.export(data)
                if config.getint('output') & config.OUT_SHIP:
                    loadout.export(data)

                if not (config.getint('output') &
                        (config.OUT_CSV | config.OUT_TD | config.OUT_BPC
                         | config.OUT_EDDN)):
                    # no further output requested
                    self.status['text'] = strftime('Last updated at %H:%M:%S',
                                                   localtime(querytime))

                elif not data['commander'].get('docked'):
                    self.status['text'] = "You're not docked at a station!"
                else:
                    if data['lastStarport'].get('commodities'):
                        # Fixup anomalies in the commodity data
                        self.session.fixup(data['lastStarport']['commodities'])

                        if config.getint('output') & config.OUT_CSV:
                            bpc.export(data, True)
                        if config.getint('output') & config.OUT_TD:
                            td.export(data)
                        if config.getint('output') & config.OUT_BPC:
                            bpc.export(data, False)

                    if config.getint('output') & config.OUT_EDDN:
                        if data['lastStarport'].get(
                                'commodities') or data['lastStarport'].get(
                                    'modules') or data['lastStarport'].get(
                                        'ships'):
                            self.status['text'] = 'Sending data to EDDN...'
                            self.w.update_idletasks()
                            eddn.export(data)
                            self.status['text'] = strftime(
                                'Last updated at %H:%M:%S',
                                localtime(querytime))
                        else:
                            self.status[
                                'text'] = "Station doesn't have anything!"
                    elif not data['lastStarport'].get('commodities'):
                        self.status['text'] = "Station doesn't have a market!"
                    else:
                        self.status['text'] = strftime(
                            'Last updated at %H:%M:%S', localtime(querytime))

        except companion.VerificationRequired:
            return prefs.AuthenticationDialog(self.w, self.verify)

        # Companion API problem
        except companion.ServerError as e:
            self.status['text'] = str(e)

        except requests.exceptions.ConnectionError as e:
            if __debug__: print_exc()
            self.status['text'] = "Error: Can't connect to EDDN"

        except requests.exceptions.Timeout as e:
            if __debug__: print_exc()
            self.status['text'] = "Error: Connection to EDDN timed out"

        except Exception as e:
            if __debug__: print_exc()
            self.status['text'] = str(e)

        self.cooldown()