# Path: blog/documents.py
# ELASTICSEARCH_ENABLED = hasattr(settings, 'ELASTICSEARCH_DSL')
# 
# class ElaspedTimeDocumentManager:
#     @staticmethod
#     def build_index():
#         from elasticsearch import Elasticsearch
#         client = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts'])
#         res = client.indices.exists(index="performance")
#         if not res:
#             ElapsedTimeDocument.init()
# 
#     @staticmethod
#     def delete_index():
#         from elasticsearch import Elasticsearch
#         es = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts'])
#         es.indices.delete(index='performance', ignore=[400, 404])
# 
#     @staticmethod
#     def create(url, time_taken, log_datetime, useragent, ip):
#         ElaspedTimeDocumentManager.build_index()
#         ua = UserAgent()
#         ua.browser = UserAgentBrowser()
#         ua.browser.Family = useragent.browser.family
#         ua.browser.Version = useragent.browser.version_string
# 
#         ua.os = UserAgentOS()
#         ua.os.Family = useragent.os.family
#         ua.os.Version = useragent.os.version_string
# 
#         ua.device = UserAgentDevice()
#         ua.device.Family = useragent.device.family
#         ua.device.Brand = useragent.device.brand
#         ua.device.Model = useragent.device.model
#         ua.string = useragent.ua_string
#         ua.is_bot = useragent.is_bot
# 
#         doc = ElapsedTimeDocument(
#             meta={
#                 'id': int(
#                     round(
#                         time.time() *
#                         1000))
#             },
#             url=url,
#             time_taken=time_taken,
#             log_datetime=log_datetime,
#             useragent=ua, ip=ip)
#         doc.save(pipeline="geoip")


import logging
import time
from ipware import get_client_ip
from user_agents import parse
from blog.documents import ELASTICSEARCH_ENABLED, ElaspedTimeDocumentManager
                    from django.utils import timezone



logger = logging.getLogger(__name__)


class OnlineMiddleware(object):
    def __init__(self, get_response=None):
        self.get_response = get_response

# Path: blog/documents.py
# ELASTICSEARCH_ENABLED = hasattr(settings, 'ELASTICSEARCH_DSL')
# 
# class ElaspedTimeDocumentManager:
#     @staticmethod
#     def build_index():
#         from elasticsearch import Elasticsearch
#         client = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts'])
#         res = client.indices.exists(index="performance")
#         if not res:
#             ElapsedTimeDocument.init()
# 
#     @staticmethod
#     def delete_index():
#         from elasticsearch import Elasticsearch
#         es = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts'])
#         es.indices.delete(index='performance', ignore=[400, 404])
# 
#     @staticmethod
#     def create(url, time_taken, log_datetime, useragent, ip):
#         ElaspedTimeDocumentManager.build_index()
#         ua = UserAgent()
#         ua.browser = UserAgentBrowser()
#         ua.browser.Family = useragent.browser.family
#         ua.browser.Version = useragent.browser.version_string
# 
#         ua.os = UserAgentOS()
#         ua.os.Family = useragent.os.family
#         ua.os.Version = useragent.os.version_string
# 
#         ua.device = UserAgentDevice()
#         ua.device.Family = useragent.device.family
#         ua.device.Brand = useragent.device.brand
#         ua.device.Model = useragent.device.model
#         ua.string = useragent.ua_string
#         ua.is_bot = useragent.is_bot
# 
#         doc = ElapsedTimeDocument(
#             meta={
#                 'id': int(
#                     round(
#                         time.time() *
#                         1000))
#             },
#             url=url,
#             time_taken=time_taken,
#             log_datetime=log_datetime,
#             useragent=ua, ip=ip)
#         doc.save(pipeline="geoip")


# Path: blog/middleware.py
import logging
import time
from ipware import get_client_ip
from user_agents import parse
from blog.documents import ELASTICSEARCH_ENABLED, ElaspedTimeDocumentManager
                    from django.utils import timezone




logger = logging.getLogger(__name__)


class OnlineMiddleware(object):
    def __init__(self, get_response=None):
        self.get_response = get_response

        super().__init__()