Example #1
0
def receivePic():
    try:
        log.endpointReached('image',request.remote_addr)
        image = objectDetect()
        print('endpoint reachde')
        if request.method == 'POST':
            print("hello world")
            data = request.json
            pic_as_base64 = data['pictureString']
            with open("imageToDetect.jpg",'wb') as fh:
                fh.write(base64.b64decode(pic_as_base64))


            imagePath = "./imageToDetect.jpg"
            imageDetected, objectList = image.processImage(imagePath)
            objects = ""
            for i in range(len(objectList)):
                objects += objectList[i] +"\n"

            os.remove("./imageToDetect.jpg")
            os.remove("./imageToDetect_yolo3.jpg")
            log.success()
            return {
                "pictureResponse": imageDetected,
                "objects": objects
            }
        if request.method == 'GET':
            return "<h1>Hello world iSeek</h1>"
    except:
        log.fail(str(sys.exec_info()))
        return "failed check system log"
Example #2
0
def receivePic():
    try:
        log.endpointReached('image', request.remote_addr)
        image = objectDetect()
        print('endpoint reached')
        if request.method == 'POST':
            print("hello world")
            data = request.json
            pic_as_base64 = data['pictureString']

            with open("imageToDetect.jpg", 'wb') as fh:
                fh.write(base64.b64decode(pic_as_base64))

            imagePath = "./imageToDetect.jpg"
            objectList = image.detect(source=imagePath)

            with open('result.jpg', 'rb') as image_file:
                imageDetected = base64.b64encode(
                    image_file.read()).decode('utf-8')

            objects = ""
            for i in range(len(objectList)):
                objects += str(objectList[i])

            os.remove("./imageToDetect.jpg")
            os.remove("./result.jpg")
            log.success()
            return {"pictureResponse": imageDetected, "objects": objectList}
        if request.method == 'GET':
            return "<h1>Hello world iSeek</h1>"
    except Exception as e:
        log.fail(str(e))
        return "failed check system log"
Example #3
0
 def test_success_timestamp_as_expected(self):
     log.enable_timestamp()
     time_format = "[%Y-%m-%d %H:%M:%S]"
     
     time = datetime.now()
     time_formatted = time.strftime(time_format)
     
     expected_log = f"{self.RESET}{self.GREEN}{self.BOLD}{time_formatted}[+] Success: {self.RESET}{self.TEXT}{self.RESET}\n"
     with patch('sys.stdout', new = StringIO()) as fake_out: 
         log.success(self.TEXT)
         self.assertEqual(fake_out.getvalue(), expected_log)
Example #4
0
def chatbot():
    log.endpointReached('chatbot', request.remote_addr)
    try:
        if request.method == 'POST':
            data = request.json
            message = data['textString']

            jsonText = json.dumps({'textString': message})

            respond = requests.post(url, json=jsonText)
            log.success()
            return {"textResponse": respond.text}

        if request.method == 'GET':
            return "<h1>Hello world iSeek</h1>"
    except Exception as e:
        log.fail(str(e))
        return "failed check system log"
Example #5
0
def receiveWav():
    log.endpointReached('recording', request.remote_addr)
    print('endpoint reached')
    if request.method == 'POST':
        #try:
        if 'file' not in request.files:
            log.write("ERROR:\nNo File Given")
            return "no file added"

        wavFile = request.files['file']

        if wavFile.filename != '':
            wavFile.save(wavFile.filename)
        else:
            return "no file name given"

        filePath = "./{}".format(wavFile.filename)

        # Android sends audio files in .m4a format
        if wavFile.filename[-4:] == ".m4a":
            voice.m4aToWav(filePath)
            #filePath = "./{}".format(wavFile.filename[:-4] + '.wav')
            filePath = os.getcwd() + "/{}".format(wavFile.filename[:-4] +
                                                  '.wav')

        text = voice.wavToText(filePath)

        os.remove(filePath)

        jsonText = json.dumps({'textString': text})

        respond = requests.post(url, json=jsonText)

        log.success()

        return {"textResponse": respond.text}

        # except Exception as e:
        #     log.fail(str(e))
        #     return "failed check system log"

    if request.method == 'GET':
        # return "<h1>Hello world iSeek</h1>"
        return chatbot.chatbot_response('hello')
Example #6
0
    def test_consistency(self):
        #create file
        log.enable_save_to_txt("approval_test_check.txt")

        log.info("testing info clean")
        log.error("testing error clean")
        log.warning("testing warning clean")
        log.success("testing success clean")

        #get its data
        to_check = ""
        with open("approval_test_check.txt", "r") as f1:
            to_check = f1.read()

        #get target data
        target = ""
        with open("approval_test_valid.txt", "r") as f2:
            target = f2.read()

        self.assertEqual(to_check, target)
Example #7
0
def recieveText():
    log.endpointReached('text', request.remote_addr)
    image = objectDetect()
    if request.method == 'POST':
        print("hello world")
        data = request.json

        pic_as_base64 = data['pictureString']
        with open("textToDetect.jpg", 'wb') as fh:
            fh.write(base64.b64decode(pic_as_base64))

        imagePath = "./textToDetect.jpg"
        text = image.readText(imagePath)

        os.remove("./textToDetect.jpg")

        log.success()
        return {
            "imageText": text,
        }
    else:
        log.fail(sys.exc_info()[0])
        return "failed check system log"
Example #8
0
 def test_success_as_expected(self):
     expected_log = f"{self.RESET}{self.GREEN}{self.BOLD}[+] Success: {self.RESET}{self.TEXT}{self.RESET}\n"
     with patch('sys.stdout', new = StringIO()) as fake_out: 
         log.success(self.TEXT)
         self.assertEqual(fake_out.getvalue(), expected_log) 
Example #9
0
		d["billingCity"] = ""
		d["billingCountry"] = None
		d["billingFirstName"] = ""
		d["billingLastName"] = ""
		d["billingMatch"] = True
		d["billingPhone"] = ""
		d["billingZipCode"] = ""
		d["cardCvv"] = y[3]
		d["cardExpiry"] = y[2]
		d["cardName"] = fname + ' ' + lname
		d["cardNumber"] = ' '.join(re.findall(r'.{1,4}',y[1]))
		d["city"] = profile["city"]
		d["country"] = profile['country']
		d["email"] = fname + '_' + lname + '@' + profile['email']
		#catchall only
		d["firstName"] = fname
		d["lastName"] = lname
		d["oneuseonly"] = False
		d["phone"] = '907' + phone
		d["state"] = profile['state-code']
		d["zipCode"] = profile['zipCode']

		p[y[0]] = {}
		p[y[0]] = d


with open('profiles.json','w+') as f:
	json.dump(p,f,sort_keys = True,indent=4)

log.success('Done!')
Example #10
0
from logger import log
#used to create a txt file used for approval testing


log.enable_save_to_txt("approval_test_valid.txt")

log.info("testing info clean")
log.error("testing error clean")
log.warning("testing warning clean")
log.success("testing success clean")

Example #11
0
from logger import log
from pathlib import Path
from logger import FGColor

# print(REVERSED + "Hola" + RESET)
# print(BOLD + "Hola")
# print(UNDERLINE + "Hola" + RESET)

log.error("An Error Occurred Unexpectedly")
log.warning("Something strange is happening")
log.success("Everything is working fine")
log.info("Something is working...")

log.enable_save_to_txt(path=Path.cwd())
log.enable_timestamp()

log.info("Some text")
log.error("Some error")

log.set_log_timestamp_format("[%H:%M]")

log.info("Other text")

log.color(FGColor.red, " .----------------. ")
log.color(FGColor.green, "|          _       |")
log.color(FGColor.yellow, "|      _.-'|'-._   |")
log.color(FGColor.blue, "| .__.|    |    |  |")
log.color(FGColor.magenta, "|     |_.-'|'-._|  |")
log.color(FGColor.cyan, "| '--'|    |    |  |")
log.color(FGColor.white, "| '--'|_.-'`'-._|  |")
log.color(FGColor.red, "| '--'          `  |")
Example #12
0
def voiceMobileNetObjectCheck():
    print("hello there")
    print(os.getcwd())
    if request.method == 'GET':
        return "<h1>Hello world iSeek</h1>"
    if request.method == 'POST':

        try:
            if 'file' not in request.files:
                log.write("ERROR:\nNo File Given")
                return "no file added"

            wavFile = request.files['file']

            if wavFile.filename != '':
                print(wavFile.filename)
                wavFile.save(wavFile.filename)

            else:
                return "no file name given"

            filePath = "./{}".format(wavFile.filename)

            # Android sends audio files in .m4a format
            if wavFile.filename[-4:] == ".m4a":

                voice.m4aToWav(filePath)
                #voice.m4aToWav("/home/iseekadmin/tempserverforaws/sample.m4a")
                filePath = os.getcwd() + "/{}".format(wavFile.filename[:-4] +
                                                      '.wav')
                #filePath = "./sample.wav"

            print(filePath)

            #filPath = os.getcwd() + "/sample.wav"
            #print(filePath)
            text = voice.wavToText(filePath)

            print(text)

            # os.remove(filePath)

            keywordCheck = False
            amazonNeeded = False
            keywords = ""

            for i in range(len(askOptions)):
                if text.lower().startswith(askOptions[i].lower()):
                    keywords = askOptions[i]
                    keywordCheck = True

            print(text, keywordCheck)
            print(len(text.split()))

            if len(text.split()) == 1 or keywordCheck:
                availabilityStatus = False
                returnObject = ""
                objectAvailability = ""
                yesNo = False
                if keywordCheck:
                    wantedObject = text.split(keywords + " ")[1]
                else:
                    wantedObject = text

                print(wantedObject)
                for i in range(len(mobileNetOptions)):
                    for j in range(len(mobileNetOptions[i])):
                        if mobileNetOptions[i][j].lower(
                        ) == wantedObject.lower():
                            availabilityStatus = True
                            yesNo = False
                            if len(mobileNetOptions[i]) == 1:
                                returnObject = mobileNetOptions[i][0]
                                print('x')
                                print(returnObject)
                                return {
                                    "amazonNeeded": amazonNeeded,
                                    "objectAvailability": availabilityStatus,
                                    "yesNoNeeded": yesNo,
                                    "objectChoice": returnObject
                                }
                            else:

                                for k in range(len(mobileNetOptions[i])):
                                    # print(mobileNetOptions[i][k])
                                    if k == len(mobileNetOptions[i]) - 1:
                                        returnObject += mobileNetOptions[i][k]
                                    else:
                                        returnObject += mobileNetOptions[i][
                                            k] + ", "
                                print('y')
                                print(returnObject)
                                return {
                                    "amazonNeeded": amazonNeeded,
                                    "objectAvailability": availabilityStatus,
                                    "yesNoNeeded": yesNo,
                                    "objectChoice": returnObject
                                }

                if not availabilityStatus:
                    print("here")
                    syns = dictionary.synonym(wantedObject)
                    print(syns)
                    for x in range(len(syns)):
                        for i in range(len(mobileNetOptions)):
                            for j in range(len(mobileNetOptions[i])):
                                if mobileNetOptions[i][j].lower(
                                ) == syns[x].lower():

                                    yesNo = True
                                    availabilityStatus = True

                                    if len(mobileNetOptions[i]) == 1:

                                        returnObject = mobileNetOptions[i][0]
                                        print('i')
                                        print(returnObject)
                                        return {
                                            "amazonNeeded": amazonNeeded,
                                            "objectAvailability":
                                            availabilityStatus,
                                            "yesNoNeeded": yesNo,
                                            "objectChoice": returnObject
                                        }

                                    else:

                                        for k in range(len(
                                                mobileNetOptions[i])):
                                            print(mobileNetOptions[i][k])
                                            if k == len(
                                                    mobileNetOptions[i]) - 1:
                                                returnObject += mobileNetOptions[
                                                    i][k]
                                            else:
                                                returnObject += mobileNetOptions[
                                                    i][k] + ", "
                                        print(returnObject)
                                        print('j')

                                        return {
                                            "amazonNeeded": amazonNeeded,
                                            "objectAvailability":
                                            availabilityStatus,
                                            "yesNoNeeded": yesNo,
                                            "objectChoice": returnObject
                                        }
                    print('k')

                    print(returnObject)

                    return {
                        "amazonNeeded": amazonNeeded,
                        "objectAvailability": availabilityStatus,
                        "yesNoNeeded": yesNo,
                        "objectChoice": returnObject
                    }

            else:
                amazonNeeded = True
                jsonText = json.dumps({'textString': text})

                respond = requests.post(url, json=jsonText)

                log.success()

                return {
                    "amazonNeeded": amazonNeeded,
                    "textResponse": respond.text
                }

        except TypeError as e:
            print(e)
            # log.fail(str(sys.exec_info()))
            return "failed, check system log"
Example #13
0
def test1():
    log.info('haozigege')
    log.success('666666')
    log.warning('warning')
    log.error('error')