Esempio n. 1
0
def download_data(group):
    service = gen.authenticate_drive_api()
    kml_file_id = gen.get_tableId_by_table_name("SSURGO_" + str(group) + ".kml", 
        service, google_service='drive')
    bytes_data = download_file(service, group, kml_file_id)
    out_file = write_download_to_file(bytes_data, group)
    delete_files_on_drive(service, group, kml_file_id)
    return out_file
Esempio n. 2
0
def delete_temp_tables():
    for file_str in os.listdir(dirs.intermediate_directory):
        if 'SSURGO_' in file_str:
            os.remove(dirs.intermediate_directory + "\\" + file_str)
    service = gen.authenticate_drive_api()
    ids = gen.get_tableId_by_table_name('SSURGO_', service, 
        exact=False, google_service='drive')
    for file_id in ids:
        service.files().trash(fileId=file_id).execute()
    service.files().emptyTrash()
Esempio n. 3
0
def download_data(eeout_file_name, local_dl_file, service):
    
    def download_file(service, eeout_file_id):
        request = service.files().get_media(fileId=eeout_file_id)
        fh = io.BytesIO()
        downloader = gac.http.MediaIoBaseDownload(fh, request)
        failure_counter = 0
        while failure_counter < 5:
            try:
                status, done = downloader.next_chunk()
                print "\t Downloading Output %d%%." % int(status.progress() * 100)
                break
            except:
                gen.exponential_backoff(failure_counter)
                failure_counter = failure_counter+1
                if(failure_counter == 5): 
                    fh=None
                    print "Failed download"
        return fh

    def write_download_to_file(bytes_data, local_dl_file):
        with open(local_dl_file, 'wb') as f:
            f.write(bytes_data.getvalue())
        return local_dl_file

    def delete_file_on_drive(service, eeout_file_id):
        failure_counter = 0
        while failure_counter < 5:
            try:
                service.files().delete(fileId=eeout_file_id).execute()
                break
            except:
                gen.exponential_backoff(failure_counter)
                failure_counter = failure_counter + 1
                if(failure_counter == 5): print "Failed deletion"

    eeout_file_id = gen.get_tableId_by_table_name(eeout_file_name, service, google_service='drive')
    if eeout_file_id is None: return
    bytes_data = download_file(service, eeout_file_id)
    if bytes_data is None: return
    out_file = write_download_to_file(bytes_data, local_dl_file)
    delete_file_on_drive(service, eeout_file_id)
Esempio n. 4
0
 def copy_template_table(service):
     template_ID = gen.get_tableId_by_table_name('Template_NCSS', service, google_service='fusion')
     request = service.table().copy(tableId = template_ID)
     response = request.execute()
     return response
Esempio n. 5
0
def delete_files_on_drive(service, group, file_id):
    service.files().delete(fileId=file_id).execute()
    ft_id = gen.get_tableId_by_table_name('SSURGO_' + str(group), service, google_service='drive')
    service.files().delete(fileId=ft_id).execute()