def submit(self, fn, callback, timeout, *args, **kwargs): with _lock: try: self.__task_queue.put(self._Task(fn, callback, timeout, *args, **kwargs), block=False) log.info(f"task queue: {self.__task_queue.qsize()}") self._adjust_thread_count() except queue.Full as full: log.warning(f"exception : {full}")
def is_valid_for_f1laps(self): if self.session_type is None: log.warning( "Attempted to send session to F1Laps without session type: %s" % self) return False if self.team_id is None: log.warning( "Attempted to send session to F1Laps without team ID: %s" % self) return False return True
def create_session(self): session = F12021Session(session_uid=self.header.sessionUID) session.session_udp_uid = self.header.sessionUID session.set_session_type(self.sessionType) if not self.sessionType: log.warning("Got Session packet without sessionType") session.track_id = self.trackId session.ai_difficulty = self.aiDifficulty if self.networkGame == 1: session.is_online_game = True if self.weather not in session.weather_ids: session.weather_ids.append(self.weather) session.start() log.debug("Session vals: season %s weekend %s session %s UID %s" % (self.seasonLinkIdentifier, self.weekendLinkIdentifier, self.sessionLinkIdentifier, self.header.sessionUID)) return session
def check_version(self): try: response = requests.get(F1LAPS_VERSION_ENDPOINT) version = response.json()['version'] user_version_int = int(self.app_version.replace(".", "")) current_version_int = int(version.replace(".", "")) if version > self.app_version: self.app_version_label.setText( "There's a new app version available (you're on v%s).<br><a href='https://www.f1laps.com/telemetry'>Click here to download the new version!</a>" % self.app_version) self.app_version_label.setStyleSheet("color: #B45309") elif version < self.app_version: self.app_version_label.setText( "This is pre-release version v%s (stable version is v%s)." % (self.app_version, version)) self.app_version_label.setStyleSheet("color: #059669") except Exception as ex: log.warning( "Couldn't get most recent version from F1Laps due to: %s" % ex)
def run(self): """ Return if user is authenticated and supports telemetry (user_is_valid, user_telemetry_enabled)""" user_settings_dict = { "api_key_valid": False, "telemetry_enabled": False, "subscription_plan": None, "subscription_expires": None } try: log.info("Validating API key...") headers = {'Authorization': 'Token %s' % self.api_key,} response = requests.get(F1LAPS_USER_SETTINGS_ENDPOINT, headers=headers) if response.status_code == 401: log.warning("API key %s is invalid" % self.api_key) self.user_settings.emit(user_settings_dict) elif response.status_code == 200: json_response = json.loads(response.content) telemetry_enabled = json_response.get('telemetry_enabled') subscription_plan = json_response.get('subscription_plan') subscription_expires = json_response.get('subscription_expires') log.info("Authenticated against F1Laps API successfully. Telemetry is %s" % \ ("enabled" if telemetry_enabled else "not enabled")) user_settings_dict["api_key_valid"] = True user_settings_dict["telemetry_enabled"] = telemetry_enabled user_settings_dict["subscription_plan"] = subscription_plan user_settings_dict["subscription_expires"] = subscription_expires self.user_settings.emit(user_settings_dict) else: log.warning("Received invalid F1Laps status code %s" % response.status_code) self.user_settings.emit(user_settings_dict) except Exception as ex: log.warning("Couldn't get user settings from F1Laps due to: %s" % ex) self.user_settings.emit(user_settings_dict) self.finished.emit()