1
- from nbgitpuller .plugin_hook_specs import hookimpl
2
- from nbgitpuller_downloader_plugins_util .plugin_helper import HandleFilesHelper
3
1
import re
4
2
import asyncio
5
3
import aiohttp
4
+ import nest_asyncio
5
+ from nbgitpuller .plugin_hook_specs import hookimpl
6
+ from nbgitpuller_downloader_plugins_util .plugin_helper import HandleFilesHelper
7
+
8
+ # this allows us to nest usage of the event_loop from asyncio
9
+ # being used by tornado in jupyter distro
10
+ # Ref: https://medium.com/@vyshali.enukonda/how-to-get-around-runtimeerror-this-event-loop-is-already-running-3f26f67e762e
11
+ nest_asyncio .apply ()
6
12
7
13
DOWNLOAD_URL = "https://docs.google.com/uc?export=download"
8
14
@@ -78,31 +84,31 @@ async def download_archive_for_google(repo=None, temp_download_file=None):
78
84
"""
79
85
yield "Downloading archive ...\n "
80
86
try :
81
- id = get_id (repo )
82
- CHUNK_SIZE = 1024
87
+ file_id = get_id (repo )
88
+ chunk_size = 1024
83
89
async with aiohttp .ClientSession () as session :
84
- async with session .get (DOWNLOAD_URL , params = {'id' : id }) as response :
90
+ async with session .get (DOWNLOAD_URL , params = {'id' : file_id }) as response :
85
91
token = get_confirm_token (session , repo )
86
92
if token :
87
- params = {'id' : id , 'confirm' : token }
93
+ params = {'id' : file_id , 'confirm' : token }
88
94
response = await session .get (repo , params = params )
89
- with open (temp_download_file , 'ab' ) as fd :
95
+ with open (temp_download_file , 'ab' ) as file_handle :
90
96
count_chunks = 1
91
97
while True :
92
98
count_chunks += 1
93
99
if count_chunks % 1000 == 0 :
94
100
display = count_chunks / 1000
95
101
yield f"Downloading Progress ... { display } MB\n "
96
- chunk = await response .content .read (CHUNK_SIZE )
102
+ chunk = await response .content .read (chunk_size )
97
103
if not chunk :
98
104
break
99
- fd .write (chunk )
105
+ file_handle .write (chunk )
100
106
yield "Archive Downloaded....\n "
101
- except Exception as e :
102
- raise e
107
+ except Exception as ex :
108
+ raise ex
103
109
104
110
105
- async def get_response_from_drive (url , id ):
111
+ async def get_response_from_drive (url , file_id ):
106
112
"""
107
113
You need to check to see that Google Drive has not asked the
108
114
request to confirm that they disabled the virus scan on files that
@@ -112,15 +118,15 @@ async def get_response_from_drive(url, id):
112
118
parameter.
113
119
114
120
:param str url: the google download URL
115
- :param str id : the google id of the file to download
121
+ :param str file_id : the google id of the file to download
116
122
:return response object
117
123
:rtype json object
118
124
"""
119
125
async with aiohttp .ClientSession () as session :
120
- async with session .get (url , params = {'id' : id }) as response :
126
+ async with session .get (url , params = {'id' : file_id }) as response :
121
127
token = get_confirm_token (session , url )
122
128
if token :
123
- params = {'id' : id , 'confirm' : token }
129
+ params = {'id' : file_id , 'confirm' : token }
124
130
response = await session .get (url , params = params )
125
131
return response
126
132
return response
@@ -140,6 +146,6 @@ def determine_file_extension_from_response(response):
140
146
ext = fname .split ("." )[1 ]
141
147
142
148
if ext is None :
143
- m = f"Could not determine compression type of: { content_disposition } "
144
- raise Exception (m )
149
+ message = f"Could not determine compression type of: { content_disposition } "
150
+ raise Exception (message )
145
151
return ext
0 commit comments