incremental pull from google drive using python

149 views Asked by At

i am new to python api and i am trying to download files from google drive on incremental bases. I am able to download file but not on incremental basis. I have used the steps provided in youtube. Could anyone help me in automating file download from google drive. Thank in advance.

1

There are 1 answers

3
NightEye On BEST ANSWER

You want to automate your python script to download new/modified files?

If so, then you can utilize Window's Task Scheduler for Windows or cron for Linux to run your python script on a daily basis.

Next is we need to define new/modified files. How do we identify if a file is new or recently modified? Since we already have automated our script to run on a daily basis, we need to check if there are new or recently modified files in the drive. This is where parameter q comes in.

Use query to search for files which were created or modified 1 day before your daily triggered time.

Then integrate your query to search for specific files and download them.

List down files matching the query:

# Call the Drive v3 API
results = service.files().list(
    pageSize=10,
    fields="nextPageToken, files(id, name)",
    q="modifiedTime > '2021-07-27T12:00:00-08:00'"
    ).execute()
items = results.get('files', [])
if not items:
    print('No files found.')
else:
    print('Files:')
    for item in items:
        print('{0} ({1})'.format(item['name'], item['id']))

Note:

  • Sample code above needs to be modified for generating the time based on the daily triggered time and downloading the files. Above code is just a sample for showing how query looks.

References: