storage.py 816 B

1234567891011121314151617181920212223242526272829303132
  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']
  14. if name == 'null':
  15. name = storage['Location']
  16. print(f'{name}: {item["MaterialAmount"]} {item["MaterialTicker"]}')
  17. class Storage(typing.TypedDict):
  18. Name: str
  19. Location: str
  20. StorageItems: typing.Sequence[StorageItem]
  21. class StorageItem(typing.TypedDict):
  22. MaterialTicker: str
  23. MaterialAmount: int
  24. if __name__ == '__main__':
  25. main()