pass

oldmessagenum = -1
filepath = ""
while True:
    messagenum, message = dmp.receive(ydid,rdid)
    print messagenum,message
    if messagenum == oldmessagenum:
        continue
    if message == "Done!":
        print "File successfully downloaded! Saved to: {}".format(filepath)
        break
    if messagenum == 0:
        try:
            filepath = os.path.join(path,os.path.basename(message))
            open(filepath,"w").close()
        except:
            print "Sender sent bad filename"
            break
    else:
        data = urllib2.urlopen("https://dl.dropboxusercontent.com/u/{}/{}".format(rdid,message)).read()
        with open(filepath,"ab") as outfile:
            outfile.write(data)

    dmp.send(messagenum,"Received!",rdid)
    oldmessagenum = messagenum

try:
    os.remove(os.path.join(dmp.dropbox_folder,"dmp{}".format(rdid)))
except:
    pass
if not os.path.isfile(filepath):
    print "File not found"
    exit()

try:
    os.remove(os.path.join(dmp.dropbox_folder,"dmp{}".format(rdid)))
except:
    pass

messagenum = 0
fileoff = 0
maxsize = os.path.getsize(filepath)
try:
    while True:
        if messagenum == 0:
            dmp.send(messagenum,os.path.basename(filepath),rdid)
            while True:
                rmessagenum, message = dmp.receive(ydid,rdid)
                if rmessagenum == messagenum and message == "Received!":
                    break

            messagenum += 1
            continue

        if fileoff >= maxsize:
            dmp.send(messagenum,"Done!",rdid)
            print "Successfully sent message!"
            break

        with open(filepath,"rb")as infile:
            infile.seek(fileoff)
示例#3
0
if not os.path.isfile(filepath):
    print "File not found"
    exit()

try:
    os.remove(os.path.join(dmp.dropbox_folder, "dmp{}".format(rdid)))
except:
    pass

messagenum = 0
fileoff = 0
maxsize = os.path.getsize(filepath)
try:
    while True:
        if messagenum == 0:
            dmp.send(messagenum, os.path.basename(filepath), rdid)
            while True:
                rmessagenum, message = dmp.receive(ydid, rdid)
                if rmessagenum == messagenum and message == "Received!":
                    break

            messagenum += 1
            continue

        if fileoff >= maxsize:
            dmp.send(messagenum, "Done!", rdid)
            print "Successfully sent message!"
            break

        with open(filepath, "rb") as infile:
            infile.seek(fileoff)