예제 #1
0
def test_saveFile():
    '''test saving files locally
    '''
    remote_data = functions.downloadFile('/test/test-download.jpg')
    written = functions.saveFile('', 'test-save.jpg', remote_data)

    assert len(remote_data) == written
예제 #2
0
def test_downloadFile():
    '''test downloading files
    '''
    remote_data = functions.downloadFile('/test/test-download.jpg')

    path = os.path.join(os.environ['BASE'], os.environ['FOLDER'],
                        os.environ['SUB_FOLDER'], 'test-download.jpg')
    with open(path, 'rb') as f:
        local_data = f.read()

    assert remote_data == local_data
예제 #3
0
def startProcess(fileType, downloadAmount, config):
    #setup
    mainPath = config[0]
    moviePath = config[1]
    showPath = config[2]
    filePath = config[3]
    recyclePath = config[4]
    # get auto settings
    downloadPath = mainPath+'/downloads/'+fileType+'s'
    if moviePath is '':
        moviePath = mainPath+'/movies'
    if showPath is '':
        showPath = mainPath+'/shows'
    if filePath is '':
        filePath = mainPath+'/files'
    if recyclePath is '':
        recyclePath = mainPath+'/recycle/'+fileType+'s'
    tempFolder = os.path.exists(downloadPath)
    os.chdir(mainPath+'/downloads')
    if tempFolder:
        timeStamp = time.strftime('%d%m%Y%I%M%S')
        os.rename(fileType+'s', fileType+'s_'+timeStamp)
    os.makedirs(downloadPath)
    # Start process
    print('-----------------------------=['+fileType+' Process started]')
    # Set varibles needed
    if fileType is 'movie':
        mediaPath = moviePath
    elif fileType is 'show':
        mediaPath = showPath
    elif fileType is 'file':
        mediaPath = filePath
    # Count the number of links avalible to download
    print('[Checking '+fileType+' links]')
    linkAmount = functions.countLinks(fileType)
    # Make sure everything is downloaded if no manual amount set
    if downloadAmount is False:
        downloadAmount = linkAmount
    # Loop over downloadable links
    processedAmount = 0
    while True:
        # print('[Download started]')
        downloadProcess = functions.downloadFile(fileType, downloadPath, mainPath)
        processedAmount = processedAmount + 1
        #  print ('[ '+processedAmount ' of ' linkAmount ' downloaded]')
        if processedAmount is downloadAmount:
            print('[Done]')
            break
        if downloadProcess is False:
            break
    if fileType is not 'file':
        # unzip downloaded files
        rarExists = functions.unzipFile(fileType, downloadPath)
        if downloadProcess is not False:
            # format filenames
            functions.renameFile(downloadPath)
            # check for duplicates
            functions.moveFiles(downloadPath, mediaPath, recyclePath)
    # record to logs
    shutil.rmtree(downloadPath)
    print('[End of '+fileType+'s]')
예제 #4
0
import functions

while True:
    print('Looking for link...')
    functions.downloadFile('file', '/mnt/usbstorage/downloads/files', '/mnt/usbstorage/downloads/files')