__init__.py 684 B

123456789101112131415161718192021222324252627282930313233
  1. import requests
  2. import json
  3. class SnowflakeClient(object):
  4. def __init__(self, host, port):
  5. self.host = host
  6. self.port = port
  7. self.api_uri = 'http://%s:%s/' % (self.host, self.port)
  8. def get_guid(self):
  9. res = requests.get(self.api_uri)
  10. return int(res.text)
  11. def get_stats(self):
  12. res = requests.get(self.api_uri + 'stats')
  13. return json.loads(res.text)
  14. default_client = SnowflakeClient('localhost', 8910)
  15. def setup(host, port):
  16. global default_client
  17. default_client = SnowflakeClient(host, port)
  18. def get_guid():
  19. return default_client.get_guid()
  20. def get_stats():
  21. return default_client.get_stats()