Ejemplo n.º 1
0
def convertToContactDto(value) :
    if isinstance(value, ContactDto.ContactRequestDto) :
        return value
    else :
        returnValue = None
        try :
            returnValue = Serializer.convertFromJsonToObject(Serializer.getObjectAsDictionary(value), ContactDto.ContactRequestDto)
        except :
            returnValue = value
        return returnValue
Ejemplo n.º 2
0
 def buildModelFromMessageScanResponseDto(self, messageScanDto, conversationKey) :
     errorList = messageScanDto['errorList']
     soup = SoupUtil.getSoupFromHtml(messageScanDto['html'])
     ownerInfo = SoupUtil.getText(
         SoupUtil.getValue(
             SoupUtil.findByPartialAttributeValue(soup, 'div', 'class', 'copyable-text'),
             'data-pre-plain-text'
         )
     )
     ownerKey = ownerInfo.split(']')[-1].strip()
     ownerKey = ownerKey if not ownerKey.endswith(':') else ownerKey[:-1]
     now = DateTimeHelper.dateTimeNow()
     postedAt = ownerInfo.split(']')[0].split('[')[-1].strip().split()
     postedAt = f'{StringHelper.join(postedAt[-1].split("/")[::-1], character="-")} {postedAt[0]}:{str(now).split(":")[-1]}'
     return Message.Message(
         key = messageScanDto['key'],
         conversationKey = conversationKey,
         ownerKey = ownerKey,
         postedAt = postedAt,
         ownerInfo = ownerInfo,
         scannedAt = now,
         text = SoupUtil.getText(SoupUtil.findByPartialAttributeValue(soup, 'span', 'class', 'selectable-text copyable-text')),
         originalAsText = SoupUtil.getText(soup),
         originalAsHtml = messageScanDto['html'],
         isPoolerMessage = 'message-out' in SoupUtil.getValue(SoupUtil.findTag(soup, 'div'), 'class'),
         poolingStatus = PoolingStatus.SUCCESS,
         errorCount = len(errorList),
         errorListAsJson = Serializer.jsonifyIt(errorList)
     )
 def evaluateText(self, witAiParamsRequest) :
     headers = {'Authorization': WitAiConfig.AUTHORIZATION, 'Content-type': 'application/json', 'Accept': 'text/plain'}
     params = Serializer.getObjectAsDictionary(witAiParamsRequest)
     params['v'] = str(WitAiConfig.APP_ID)
     response = requests.get(MESSAGE_URL, headers=headers, params=params)
     if 399 < response.status_code :
         raise GlobalException(
             message = self.getErrorMessage(response),
             status = HttpStatus.map(response.status_code),
             logMessage = 'Error at client call'
         )
     return response.json(), HttpStatus.map(response.status_code)
Ejemplo n.º 4
0
def toWriteResponseDtoList(messageList):
    if ObjectHelper.isNotNone(messageList):
        return Serializer.convertFromObjectToObject(
            messageList, [[MessageWriteDto.MessageWriteResponseDto]])
    return MessageConstants.EMPTY_MESSAGE_LIST
Ejemplo n.º 5
0
def toWriteRequestDto(message):
    if ObjectHelper.isNotNone(message):
        return Serializer.convertFromObjectToObject(
            message, [MessageWriteDto.MessageWriteRequestDto])
    return message
Ejemplo n.º 6
0
def toReadResponseDto(message):
    if ObjectHelper.isNotNone(message):
        return Serializer.convertFromObjectToObject(
            message, [MessageScanDto.MessageScanResponseDto])
    return message