MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / download_links

Function download_links

utils/src/experiment/crawler.py:181–216  ·  view source on GitHub ↗
(jsonl_file: str)

Source from the content-addressed store, hash-verified

179
180
181async def download_links(jsonl_file: str) -> None:
182 async with aiohttp.ClientSession() as session:
183 with jsonlines.open(jsonl_file) as reader:
184 tasks = list(reader)
185 progress_bar = tqdm(total=len(tasks), desc="Downloading files")
186 task_iter = iter(tasks)
187 coroutines = []
188 while True:
189 while len(coroutines) < 80:
190 task = next(task_iter, None)
191 if task is None:
192 break
193 dirname = f"zenodo-pptx/pptx/{task['license']}/{task['created'][:4]}/"
194 basename = f"{task['checksum'][4:]}-{task['filename']}"
195 filepath = dirname + basename
196 try:
197 open("/tmp/" + basename, "wb").close()
198 except:
199 filepath = dirname + basename[:240] + ".pptx"
200 if os.path.exists(filepath):
201 progress_bar.update(1)
202 continue
203 coroutines.append(
204 download_file(session, filepath, task["url"], progress_bar)
205 )
206
207 start_time = time.time()
208 results = await asyncio.gather(*coroutines, return_exceptions=True)
209 for result in results:
210 if isinstance(result, Exception):
211 tqdm.write(f"Error {result}")
212 if len(coroutines) % 80 != 0:
213 return
214 coroutines.clear()
215 elapsed_time = time.time() - start_time
216 sleep(max(60 - elapsed_time, 0))
217
218
219async def gather_files(topics: list[str], num_results: int) -> None:

Callers 1

crawler.pyFile · 0.70

Calls 3

download_fileFunction · 0.70
closeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected