def existsGraph(self, accountId: str): path = Path(getGraphPath(accountId)) if path.exists(): return HttpResponse({"status": "OK"}) return HttpResponse({"status": "NOT_FOUND"})
def requestId(self, new=False): """ Generates the ID for the user :param new: If True requests a new ID, even if one exists already :return: The ID """ if not new: if 'userId' in self.request.session: return HttpResponse({'id': self.request.session['userId'], 'status': 'SESSION'}) userId = createId(self.request) self.request.session['userId'] = userId return HttpResponse({'id': userId, 'status': 'NEW'})
def downloadDataFor(self, playerId: int): pl = PeerLoader(self._getClientManager()) pl.load(PLAYER_ID) time.sleep(5) return HttpResponse({"status": "Done"})
def get(self, request: WSGIRequest, nbr1, nbr2, name): path = f'{Config.PROFILE_PICTURES_FOLDER}/{nbr1}/{nbr2}/{name}' try: with open(path, 'rb') as file: return HttpResponse(file.read(), content_type='image/png') except FileNotFoundError: raise Http404(f"Path '{path}' not found.")
def onPlayerIdFormSubmit(self, playerId: str): clientManager = self._getClientManager() if not playerId or playerId == '': return HttpResponse({'status': 'INVALID_ID'}) try: player = clientManager.getSinglePlayer(int(playerId)) except PlayerNotExistError: return HttpResponse({'status': 'PLAYER_NOT_EXISTING'}) self.request.session['selectedPlayerId'] = player.accountId context = { } context.update(PlayerInfoData(playerId=playerId).toDict()) return HttpResponse(context)
def get(self, request: WSGIRequest, accountId: int): path = Path(getGraphPath(accountId)) try: with open(path.as_posix(), 'r') as file: pageData = file.read() return HttpResponse(pageData) except FileNotFoundError: raise Http404(f"No graph for player {accountId} found.")
def onStartGenerationClick(self): player = Player.objects.get(accountId=self.request.session.get('selectedPlayerId', None)) gen = GraphGenerator(player) nt = gen.generateGraph() path = Path(getGraphPath(player.accountId)) if not path.parent.exists(): path.parent.mkdir(parents=True, exist_ok=True) nt.save_graph(path.as_posix()) return HttpResponse({"status": 'OK'})
def checkAgentConnected(self): response = { 'connected': False } userId = self.request.session['userId'] if 'userId' in self.request.session else None if userId: conn = Connections.objects.filter(user_id=f'id_{userId}') if conn: response['connected'] = True return HttpResponse(response)
def test(request: WSGIRequest): def getChannelId(): connections = Connections.objects.filter(user_id='id_12345') if len(connections) == 0: return -1 elif len(connections) > 1: return 2 return connections.first().channel_id Player.objects.all().delete() pl = PeerLoader(getChannelId(), get_channel_layer()) pl.load(PLAYER_ID) return HttpResponse('Testing...')