Esempio n. 1
0
 def fire_sticker_tasks():
     from GatewayApp.requesters.stickers_requester import StickersRequester
     if Queue._sticker_status == 1:
         return
     else:
         Queue._sticker_status = 1
     print('Firing sticker tasks...')
     itasks = list(filter(lambda x: x['type'] == Queue.STICKER,
                          Queue.queue))
     ir = StickersRequester()
     tasks_to_delete = []
     for task in itasks:
         if task['request'].method == 'POST':
             _, code = ir.post_sticker(task['request'], task['data'])
         elif task['request'].method == 'PATCH':
             _, code = ir.patch_sticker(task['request'], task['uuid'],
                                        task['data'])
         elif task['request'].method == 'DELETE':
             _, code = ir.delete_sticker(task['request'], task['uuid'])
         else:
             code = 501
         if code < 500:
             tasks_to_delete.append(task)
     for task in tasks_to_delete:
         Queue.queue.remove(task)
     print(f'{len(tasks_to_delete)} image tasks fired with success')
Esempio n. 2
0
 def _delete_sticker_from_storie(self, request, storie_json: dict) -> Tuple[dict, int]:
     from GatewayApp.requesters.stickers_requester import StickersRequester
     if storie_json['sticker_uuid']:
         del_json, code = StickersRequester().delete_sticker(request, storie_json['sticker_uuid'])
         if code not in (204, 404):
             return del_json, code
     return {}, 204
Esempio n. 3
0
 def __get_and_set_storie_sticker(self, storie: dict) -> dict:
     from GatewayApp.requesters.stickers_requester import StickersRequester
     sticker_uuid = storie['sticker_uuid']  # Можеть быть кей еррор, поймаем в гет_сторис
     if sticker_uuid is not None:
         sticker_json, sticker_status = StickersRequester().get_concrete_sticker(request=None, uuid=sticker_uuid)
         if sticker_status != 200:
             from Gateway.settings import DEBUG
             if DEBUG:
                 print(sticker_json)
             raise StickerGetError(code=sticker_status, err_json=sticker_json)
         storie['sticker'] = sticker_json
     return storie
Esempio n. 4
0
 def post_storie(self, request, data: dict) -> Tuple[dict, int]:
     from GatewayApp.requesters.music_requester import MusicRequester
     from GatewayApp.requesters.stickers_requester import StickersRequester
     # check_json, code = self._check_if_attachments_exist(request, data)
     # Прикрепление юзера и проверка что он вообще есть
     try:
         if not self._check_if_user_exists(request, data['to_user_id']):
             return {'error': 'No user found with given id'}, 404
     except KeyError:
         return {'error': 'No to_user_id key was given'}, 400
     data, code = self._add_from_user_id_to_data(request, data)
     if code != 200:
         return data, code
     # ПОСТ музыки
     try:
         upload_json, code = MusicRequester().post_music(request, data['music'])
         if code != 201:
             return upload_json, code
         data['music_uuid'] = upload_json['uuid']
     except KeyError:
         pass
     # ПОСТ стикера
     try:
         upload_json, code = StickersRequester().post_sticker(request, data['sticker'])
         if code != 201:
             self.__music_rollback(request, data)  # Rollback если в посте стикера ошибка
             return upload_json, code
         data['sticker_uuid'] = upload_json['uuid']
     except KeyError:
         pass
     # Пост самой сторис
     response = self.perform_post_request(self.HOST, data=data)
     if response is None:
         self.__attachments_rollback(request, data)
         return Requester.ERROR_RETURN
     resp_json = self.get_valid_json_from_response(response)
     if response.status_code != 201:
         self.__attachments_rollback(request, data)
         return resp_json, response.status_code
     try:
         resp_json = self.__get_and_set_storie_users(request, resp_json)
     except KeyError:
         return {'error': 'Key error was raised while getting user json!'}, 500
     except UserGetError as e:
         return e.err_msg, e.code
     return resp_json, response.status_code
Esempio n. 5
0
 def __sticker_rollback(self, request, data: dict):
     from GatewayApp.requesters.stickers_requester import StickersRequester
     try:
         StickersRequester().delete_sticker(request, data['sticker_uuid'])
     except KeyError:
         pass
Esempio n. 6
0
 def _check_if_sticker_exists(self, sticker_uuid) -> bool:
     from GatewayApp.requesters.stickers_requester import StickersRequester
     _, code = StickersRequester().get_concrete_sticker(request=None, uuid=sticker_uuid)
     return code == 200
Esempio n. 7
0
class BaseStickerView(APIView):
    REQUESTER = StickersRequester()