# Path: framework/knowledge/feedback_collector.py
# class FeedbackSource(object):
# 
#     def __init__(self, src, subref=None, reliability=None, related_tg=None):
#         self._subref = subref
#         self._name = str(src) if subref is None else str(src) + ' - ' + str(subref)
#         self._obj = src
#         self._reliability = reliability
#         self._related_tg = related_tg
# 
#     def __str__(self):
#         return self._name
# 
#     def __hash__(self):
#         return id(self._obj)
# 
#     def __eq__(self, other):
#         return id(self._obj) == id(other._obj)
# 
#     @property
#     def obj(self):
#         return self._obj
# 
#     @property
#     def related_tg(self):
#         return self._related_tg
# 
# Path: libs/utils.py
# def ensure_dir(f):
#     d = os.path.dirname(f)
#     if not os.path.exists(d):
#         os.makedirs(d)
# 
# def chunk_lines(string, length):
#     l = string.split(' ')
#     chk_list = []
#     full_line = ''
#     for wd in l:
#         full_line += wd + ' '
#         if len(full_line) > (length - 1):
#             chk_list.append(full_line)
#             full_line = ''
#     if full_line:
#         chk_list.append(full_line)
#     # remove last space char
#     if chk_list:
#         chk_list[-1] = (chk_list[-1])[:-1]
#     return chk_list


import sys
import os
import re
import math
import threading
import framework.global_resources as gr
import libs.external_modules as em
from datetime import datetime
from framework.knowledge.feedback_collector import FeedbackSource
from libs.external_modules import *
from libs.utils import ensure_dir, chunk_lines
            )

        if records:
            base_dir = gr.exported_data_folder
            prev_export_date = None
            export_cpt = 0

            for rec in records:
                data_id, data_type, dm_name, sent_date, content = rec

                file_extension = dm_name

                if sent_date is None:
                    current_export_date = datetime.now().strftime("%Y-%m-%d-%H%M%S")
                else:
                    current_export_date = sent_date.strftime("%Y-%m-%d-%H%M%S")

                if current_export_date != prev_export_date:
                    prev_export_date = current_export_date
                    export_cpt = 0
                else:
                    export_cpt += 1

                export_fname = '{typ:s}_{date:s}_{cpt:0>2d}.{ext:s}'.format(
                    date=current_export_date,
                    cpt=export_cpt,
                    ext=file_extension,
                    typ=data_type)

                export_full_fn = os.path.join(base_dir, dm_name, export_fname)

# Path: framework/knowledge/feedback_collector.py
# class FeedbackSource(object):
# 
#     def __init__(self, src, subref=None, reliability=None, related_tg=None):
#         self._subref = subref
#         self._name = str(src) if subref is None else str(src) + ' - ' + str(subref)
#         self._obj = src
#         self._reliability = reliability
#         self._related_tg = related_tg
# 
#     def __str__(self):
#         return self._name
# 
#     def __hash__(self):
#         return id(self._obj)
# 
#     def __eq__(self, other):
#         return id(self._obj) == id(other._obj)
# 
#     @property
#     def obj(self):
#         return self._obj
# 
#     @property
#     def related_tg(self):
#         return self._related_tg
# 
# Path: libs/utils.py
# def ensure_dir(f):
#     d = os.path.dirname(f)
#     if not os.path.exists(d):
#         os.makedirs(d)
# 
# def chunk_lines(string, length):
#     l = string.split(' ')
#     chk_list = []
#     full_line = ''
#     for wd in l:
#         full_line += wd + ' '
#         if len(full_line) > (length - 1):
#             chk_list.append(full_line)
#             full_line = ''
#     if full_line:
#         chk_list.append(full_line)
#     # remove last space char
#     if chk_list:
#         chk_list[-1] = (chk_list[-1])[:-1]
#     return chk_list


# Path: framework/database.py
import sys
import os
import re
import math
import threading
import framework.global_resources as gr
import libs.external_modules as em
from datetime import datetime
from framework.knowledge.feedback_collector import FeedbackSource
from libs.external_modules import *
from libs.utils import ensure_dir, chunk_lines

            )

        if records:
            base_dir = gr.exported_data_folder
            prev_export_date = None
            export_cpt = 0

            for rec in records:
                data_id, data_type, dm_name, sent_date, content = rec

                file_extension = dm_name

                if sent_date is None:
                    current_export_date = datetime.now().strftime("%Y-%m-%d-%H%M%S")
                else:
                    current_export_date = sent_date.strftime("%Y-%m-%d-%H%M%S")

                if current_export_date != prev_export_date:
                    prev_export_date = current_export_date
                    export_cpt = 0
                else:
                    export_cpt += 1

                export_fname = '{typ:s}_{date:s}_{cpt:0>2d}.{ext:s}'.format(
                    date=current_export_date,
                    cpt=export_cpt,
                    ext=file_extension,
                    typ=data_type)

                export_full_fn = os.path.join(base_dir, dm_name, export_fname)

                ensure_dir(export_full_fn)