influxdb.py 671 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter database
  5. name:influxdb.py
  6. author:rabin
  7. """
  8. from influxdb import InfluxDBClient
  9. class Influxdb(object):
  10. instance = None
  11. def __new__(cls, *args, **kwd):
  12. if Influxdb.instance is None:
  13. Influxdb.instance = object.__new__(cls, *args, **kwd)
  14. return Influxdb.instance
  15. def __init__(self, config):
  16. self.connect = InfluxDBClient(config['host'], config['port'], config['username'], config['password'], config['dbname'])
  17. self.create(config['dbname'])
  18. def get(self):
  19. return self.connect
  20. def create(self, name):
  21. database = self.connect.get_list_database()
  22. self.connect.create_database(name)