Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
holoviz
GitHub Repository: holoviz/panel
Path: blob/main/scripts/gallery/collect_thumbnails.py
2012 views
1
import asyncio
2
import pathlib
3
4
import aiohttp
5
6
THUMBNAIL_URL = 'https://assets.holoviz.org/panel'
7
GALLERY_DIR = pathlib.Path(__file__).parent.parent.parent / 'examples' / 'gallery'
8
THUMBNAIL_DIR = GALLERY_DIR / 'thumbnails'
9
GALLERY_ITEMS = GALLERY_DIR.glob('*.ipynb')
10
THUMBNAIL_DIR.mkdir(exist_ok=True)
11
12
async def download(path, name, session):
13
filename = f'{name[:-6].lower()}.png'
14
url = f'{THUMBNAIL_URL}/{path}/{filename}'
15
async with session.get(url) as response:
16
if response.content_type != 'image/png':
17
return
18
with open(THUMBNAIL_DIR / filename, "wb") as f:
19
f.write(await response.read())
20
21
async def download_all():
22
async with aiohttp.ClientSession() as session:
23
await asyncio.gather(
24
*[download(item.parent.name, item.name, session) for item in GALLERY_ITEMS]
25
)
26
27
asyncio.run(download_all())
28
29