Пример #1
0
    def get_log_items_as_entries(self, attribute_dict=dict(), lookback_days=1):
        """
        Return log items not as text, good for diagnostics

        :param attribute_dict: dictionary of attributes to return logs for
        :return: list of 4-typles: timestamp, level, text, attributes
        """

        cutoff_date = datetime.datetime.now() - datetime.timedelta(
            days=lookback_days)
        timestamp_dict = {}
        timestamp_dict["$gt"] = datetime_to_long(cutoff_date)
        attribute_dict[TIMESTAMP_ID] = timestamp_dict

        result_dict = self._mongo.collection.find(attribute_dict)
        # from cursor to list...
        results_list = [single_log_dict for single_log_dict in result_dict]

        # ... to list of log entries
        results = [
            logEntry.log_entry_from_dict(single_log_dict)
            for single_log_dict in results_list
        ]

        # sort by log ID
        results.sort(key=lambda x: x._log_id)

        return results
Пример #2
0
    def store_message(self, body, subject):
        datetime_now = datetime_to_long(datetime.datetime.now())

        object_dict = dict(
            type=STORED_MSG, subject=subject, datetime=datetime_now, body=body
        )
        self._mongo.collection.insert_one(object_dict)
Пример #3
0
    def __init__(self,
                 text,
                 log_timestamp=None,
                 msglevel=0,
                 input_attributes={},
                 log_id=0):

        use_attributes = copy(input_attributes)
        log_dict = copy(use_attributes)

        msg_level_text = MSG_LEVEL_DICT["m%d" % msglevel]

        if log_timestamp is None:
            log_timestamp = datetime.datetime.now()
        log_timestamp_aslong = datetime_to_long(log_timestamp)

        log_dict[LEVEL_ID] = msglevel
        log_dict[TIMESTAMP_ID] = log_timestamp_aslong
        log_dict[TEXT_ID] = text
        log_dict[LOG_RECORD_ID] = log_id

        self._log_dict = log_dict

        self._use_attributes = use_attributes
        self._text = text
        self._msglevel = msglevel
        self._msglevel_text = msg_level_text
        self._timestamp_as_long = log_timestamp_aslong
        self._timestamp = log_timestamp
        self._log_id = log_id
Пример #4
0
def _generate_temp_pdf_filename(data: dataBlob) -> str:
    use_directory = get_directory_for_reporting(data)
    use_directory_resolved = get_resolved_pathname(use_directory)
    filename = "%s_%s.pdf" % (TEMPFILE_PATTERN, str(datetime_to_long(datetime.datetime.now())))
    full_filename = os.path.join(use_directory_resolved, filename)

    return full_filename
Пример #5
0
    def _record_date_of_email_type_send(self, subject, type):
        datetime_now = datetime_to_long(datetime.datetime.now())
        data_dict = {DATE_KEY: datetime_now}
        dict_of_keys = {SUBJECT_KEY: subject, TYPE_KEY: type}

        self.mongo_data.add_data(dict_of_keys=dict_of_keys,
                                 data_dict=data_dict,
                                 allow_overwrite=True)
Пример #6
0
    def delete_log_items_from_before_n_days(self, days=365):
        # need something to delete old log records, eg more than x months ago

        cutoff_date = datetime.datetime.now() - datetime.timedelta(days=days)
        attribute_dict = {}
        timestamp_dict = {}
        timestamp_dict["$lt"] = datetime_to_long(cutoff_date)
        attribute_dict[TIMESTAMP_ID] = timestamp_dict

        self._mongo.collection.remove(attribute_dict)
Пример #7
0
    def log_as_dict(self) -> dict:
        log_dict = copy(self.attributes)

        log_timestamp_as_long = datetime_to_long(self.timestamp)

        log_dict[LEVEL_ID] = self.msg_level
        log_dict[TIMESTAMP_ID] = log_timestamp_as_long
        log_dict[TEXT_ID] = self.text
        log_dict[LOG_RECORD_ID] = self.log_id

        return log_dict
Пример #8
0
    def store_message(self, body, subject):
        datetime_now = datetime_to_long(datetime.datetime.now())
        data_dict = {BODY_KEY: body}
        dict_of_keys = {
            SUBJECT_KEY: subject,
            TYPE_KEY: STORED_MSG,
            DATE_KEY: datetime_now,
        }

        self.mongo_data.add_data(dict_of_keys=dict_of_keys,
                                 data_dict=data_dict)
Пример #9
0
def from_series_of_margin_to_dict_of_entries(
        series_of_margin: seriesOfMargin) -> dict:
    series_of_dates = list(series_of_margin.index)
    list_of_keys = [
        str(datetime_to_long(date_entry)) for date_entry in series_of_dates
    ]
    list_of_values = list(series_of_margin.values)

    data_dict = dict([(key, value)
                      for key, value in zip(list_of_keys, list_of_values)])

    return data_dict
Пример #10
0
    def _record_date_of_email_type_send(self, subject, type):
        datetime_now = datetime_to_long(datetime.datetime.now())
        search_dict = dict(type=type, subject=subject)

        result_dict = self._mongo.collection.find_one(search_dict)
        if result_dict is None:
            object_dict = dict(type=type,
                               subject=subject,
                               datetime=datetime_now)
            self._mongo.collection.insert_one(object_dict)
        else:
            set_dict = {"$set": {"datetime": datetime_now}}
            self._mongo.collection.update_one(search_dict, set_dict)
Пример #11
0
def cutoff_date_as_long_n_days_before(lookback_days: int) -> int:
    cutoff_date = datetime.datetime.now() - datetime.timedelta(
        days=lookback_days)

    return datetime_to_long(cutoff_date)