Skip to content

Commit

Permalink
Better syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
TLCFEM committed Dec 13, 2024
1 parent d4e972f commit 910e9b7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/mb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,27 @@ async def __aenter__(self) -> MBClient:
async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.client.aclose()

def __iter__(self):
return self.download_pool.__iter__()

def print(self, *args, **kwargs):
self.console.print(*args, **kwargs)

async def download(self, record_id: str | uuid | list[str | uuid]):
if isinstance(record_id, list):
async def download(
self, record: str | uuid | list[str | uuid] | MBRecord | list[MBRecord]
):
if isinstance(record, list):
self.download_pool = []
self.download_size = len(record_id)
self.download_size = len(record)
self.current_download_size = 0
async with anyio.create_task_group() as tg:
for r in record_id:
for r in record:
tg.start_soon(self.download, r)

return

record_id: str = record.id if isinstance(record, MBRecord) else record

async with self.semaphore:
result = await self.client.post("/waveform", json=[str(record_id)])
self.current_download_size += 1
Expand Down Expand Up @@ -284,9 +291,9 @@ async def status(self):
async def main():
async with MBClient("http://localhost:8000", "test", "password") as client:
results = await client.search(QueryConfig())
await client.download([r.id for r in results])
await client.download(results)
fig: Figure = None # type: ignore
for result in client.download_pool:
for result in client:
fig = result.plot_spectrum(fig)
fig.legend()
fig.tight_layout()
Expand Down

0 comments on commit 910e9b7

Please sign in to comment.