Esempio n. 1
0
def removeDownloadedFiles():
  try:
    for fileId in dbconn.listFileIds():
      try:
        dFileResp = client.request("/files/" + str(fileId), raw=True)

        if dFileResp.ok:
          dFile = dFileResp.json()["file"]

        if dFileResp.status_code == 200:
          print " + (%s) %s/%s" % (fileId, getDirTree(dFile["parent_id"]), dFile['name'])
          dFileDelete = client.request("/files/delete", data={ 'file_ids': str(fileId) }, raw=True, method="POST")
          if dFileDelete.ok:
            dbconn.removeFileId(fileId)
            print "removed"
            removed_files.append((" + (%s) %s/%s" % (fileId, getDirTree(dFile["parent_id"]), dFile['name'])))
        elif dFileResp.status_code == 404:
          print " - (%s) Already removed: %s" % (fileId, dFileResp.status_code)
          dbconn.removeFileId(fileId)
        else:
          print " ? (%s) What?? %s" % (fileId, dFileResp.status_code)
      except Exception, e:
        print e
        continue

      #print "(%s) %s/%s" % (fileId, getDirTree(dfile["parent_id"]), dfile['name'])
      #print fileId
  except Exception, e:
    print e
Esempio n. 2
0
def removeDownloadedFiles():
  try:
    for fileId in dbconn.listFileIds():
      try:
        dfileUrl = client.request("/files/" + str(fileId), return_url = True)
        dfileResp = requests.request("GET", dfileUrl)

        if dfileResp.ok:
          dfile = dfileResp.json()["file"]

        if dfileResp.status_code == 200:
          print " + (%s) %s/%s" % (fileId, getDirTree(dfile["parent_id"]), dfile['name'])
          rfileUrl = client.request("/files/delete", return_url = True)
          if requests.post(rfileUrl, data={'file_ids': fileId}):
            dbconn.removeFileId(fileId)
            print "removed"
            removed_files.append((" + (%s) %s/%s" % (fileId, getDirTree(dfile["parent_id"]), dfile['name'])))
        elif dfileResp.status_code == 404:
          print " - (%s) Already removed: %s" % (fileId, dfileResp.status_code)
          dbconn.removeFileId(fileId)
        else:
          print " ? (%s) What?? %s" % (fileId, dfileResp.status_code)
      except Exception, e:
        print e
        continue

      #print "(%s) %s/%s" % (fileId, getDirTree(dfile["parent_id"]), dfile['name'])
      #print fileId
  except Exception, e:
    print e