storage.py 784 B

123456789101112131415161718192021222324252627282930
  1. from __future__ import annotations
  2. import sys
  3. import typing
  4. import httpx
  5. from config import config
  6. def main():
  7. items = frozenset(i.upper() for i in sys.argv[1:])
  8. storages: typing.Sequence[Storage] = httpx.get('https://api.punoted.net/v1/storages/user',
  9. headers={'X-Data-Token': config.punoted_api_key}).raise_for_status().json()
  10. for storage in storages:
  11. for item in storage['StorageItems']:
  12. if item['MaterialTicker'] in items:
  13. name = storage['Name'] or storage['Location']
  14. print(f'{name}: {item["MaterialAmount"]} {item["MaterialTicker"]}')
  15. class Storage(typing.TypedDict):
  16. Name: str
  17. Location: str
  18. StorageItems: typing.Sequence[StorageItem]
  19. class StorageItem(typing.TypedDict):
  20. MaterialTicker: str
  21. MaterialAmount: int
  22. if __name__ == '__main__':
  23. main()