def journal_entry(self, cmdr, is_beta, system, station, entry, state): "Called when Elite Dangerous writes to the commander's journal." if entry['event'] != 'SendText': return compress_json = json.dumps(entry) transmit_json = zlib.compress(compress_json.encode('utf-8')) for command in self.commands: if command in entry['Message']: # Get the status format: command_status_format = self.status_formats.get(command) if not command_status_format: command_status_format = 'Sent {command} Command' # Send the event if required, getting json_data back: json_data = None command_xmit_path_format = self.xmit_paths.get(command) if command_xmit_path_format: command_xmit_path = command_xmit_path_format.format(cmdr=cmdr, system=system) if '{cmdr}' in command_xmit_path_format: # FILTHY hack to figure out if it's a 'get' json_data = xmit.get(command_xmit_path) else: json_data = xmit.post(command_xmit_path, data=transmit_json, headers=xmit.COMPRESSED_OCTET_STREAM) if xmit.FAILED: # naughty global command_status_format = 'Failed to Send {command} Command' # Format and display the status text: self.helper.status(command_status_format.format( # Add variables here that you'd like to use in your status text: command=command, system=system, # We also supply the server's reply: **(json_data or {}) )) # VERY special handling, with NONE of the automatic stuff above: if "my hutton run" in entry['Message']: json_data = xmit.get('/myhuttonrun.json/{}'.format(cmdr)) if not json_data: self.helper.status("Failed to get Hutton Run data.") elif json_data['SecondCount'] == "0": self.helper.status("You have not completed a Hutton Run") else: self.helper.status("Your best Hutton Run is {}".format(json_data['TravelTime']))
def update(zipfile_url, digest): "Update using the ZIP file at ``zipfile_url`` if the ``digest`` checks out." s = xmit.get(zipfile_url, parse=False) z = pack.read_distro_string(s, digest) delete_current_version() unzip_new_version(z)
def __check_again_action(self): "Get and display exploration credits." if self.checking: return if self.fails > MAX_FAILS: self.__fail_safe() # again in case self.textvariable was None last time return try: self.checking = True path = '/explocredit.json/{}'.format(self.cmdr) json_data = xmit.get(path) self.credits = float(json_data['ExploCredits']) if self.textvariable: self.textvariable.set("at least {:,.0f}".format(self.credits)) self.fails = 0 self.refresh() except: self.fails = self.fails + 1 print 'FAIL', self.fails if self.fails > MAX_FAILS: self.__fail_safe() finally: self.checking = False
def daily_info_call(self): "Get and display the daily update." daily_data = xmit.get('/msgbox_daily_update.json') if daily_data: tkMessageBox.showinfo("Hutton Daily update", "\n".join(daily_data)) else: tkMessageBox.showinfo("Hutton Daily update", "Could not get Daily Update Data")
def influence_data_call(self): "Get and display Hutton influence data." influence_data = xmit.get('/msgbox_influence.json') if influence_data: tkMessageBox.showinfo("Hutton Influence Data", "\n".join(influence_data)) else: tkMessageBox.showinfo("Hutton Influence Data", "Could not get Influence Data")
def news_update(self): "Update the news." self.after(REFRESH_MINUTES * 60 * 1000, self.news_update) news_data = xmit.get('/news.json/{}'.format(uptime_stats)) if news_data: self['url'] = news_data['link'] self['text'] = news_data['headline'] else: self['text'] = "News refresh failed"
def news_update(self): "Update the news." self.after(REFRESH_MINUTES * 60 * 1000, self.news_update) if commander: # if we have commander name ask for specific news news_data = xmit.get('/news.json/{}'.format(commander)) if news_data: self['url'] = news_data['link'] self['text'] = news_data['headline'] else: self['text'] = "News refresh failed" else: # Get normal news news_data = xmit.get('/news.json/{}') if news_data: self['url'] = news_data['link'] self['text'] = news_data['headline'] else: self['text'] = "News refresh failed"
def get_version_info(): "Get the information on the latest version." info = xmit.get(HH_VERSION_URL) if info is None: return None version = info['version'] location = info['location'] digest = info['digest'] zipfile_url = urlparse.urljoin(HH_VERSION_URL, location) return Version(version), zipfile_url, digest
def __fetch(self): "Fetch the data again." if not self.cmdr: return if self.fetching: return try: self.fetching = True self.data = xmit.get('/day-week-stats.json/{}'.format(self.cmdr)) if self.display: self.ready = self.display.update(self.data) self.refresh() finally: self.fetching = False
def __check_again_action(self): "Get and display exploration credits." if self.checking: return if self.fails > MAX_FAILS: self.__fail_safe( ) # again in case self.textvariable was None last time return try: self.checking = True path = 'http://hot.forthemug.com:4570/closest_mug_system.json/{}'.format( self.cmdr) json_data = xmit.get(path) self.pwpnews = str(json_data['hhtext']) self.distance = float(json_data['distance']) self.hyperlink = str(json_data['hhlink']) if self.textvariable and self.hyperlink: self.textvariable.set(self.pwpnews + " ({:,.2f}lys)".format(self.distance)) for w in self.frame.winfo_children(): if "pwplink" in str(w): w['url'] = self.hyperlink self.fails = 0 self.refresh() except: self.fails = self.fails + 1 print('FAIL', self.fails) if self.fails > MAX_FAILS: self.__fail_safe() finally: self.checking = False
def __check_again_action(self): "Get and display exploration credits." if self.checking: return if self.fails > MAX_FAILS: self.__fail_safe( ) # again in case self.textvariable was None last time return if not datetime.datetime.now() > self.lastcheck + datetime.timedelta( seconds=5): #sys.stderr.write("Too soon...\r\n") return try: self.checking = True self.lastcheck = datetime.datetime.now() path = '/explocredit.json/{}'.format(self.cmdr) json_data = xmit.get(path) self.credits = float(json_data['ExploCredits']) if self.textvariable: self.textvariable.set("~ {:,.0f} Cr".format(self.credits)) self.fails = 0 self.refresh() except: self.fails = self.fails + 1 print('FAIL', self.fails) if self.fails > MAX_FAILS: self.__fail_safe() finally: self.checking = False
def __fetch(self): "Fetch the data again." if not self.cmdr: return if not datetime.datetime.now() > self.lastfetch + datetime.timedelta( seconds=5): #sys.stderr.write("Too soon...\r\n") return if self.fetching: return try: self.lastfetch = datetime.datetime.now() self.fetching = True self.data = xmit.get('/day-week-stats.json/{}'.format(self.cmdr)) if self.display: self.ready = self.display.update(self.data) self.refresh() finally: self.fetching = False
def plugin_start(self): "Called once at startup. Try to keep it short..." extra_paths = xmit.get(ADDITIONAL_PATHS_URL) if extra_paths is not None: self.event_paths = merge_dicts(self.event_paths, extra_paths)