# Path: utils/utils.py
# def get_csv_writer(csvfile):
#     return UnicodeWriter(csvfile, quoting=csv.QUOTE_ALL)
# 
# def get_json_writer(json_file):
#     return UnicodeJsonDumper(json_file)
# 
# def write_to_csv(arr_data, csv_writer):
#     """Writes contents to a CSV file using UTF-8"""
#     csv_writer.writerow(arr_data)
# 
# def write_to_json(header, arr_data, json_writer):
#     """Write data in json files using UTF-8"""
#     try:
#         json_writer.dump_json({
#             h: arr_data[index] for index, h in enumerate(header)
#         })
#     except IndexError:
#         json_writer.dump_json({
#             header[index]: d for index, d in enumerate(arr_data)
#         })
# 
# def close_json_writer(json_writer):
#     json_writer.close_current()


import win32evtlog
import datetime
import os
from utils.utils import get_csv_writer, get_json_writer, write_to_csv, write_to_json, close_json_writer
                                             event.TimeGenerated.day, event.TimeGenerated.hour,
                                             event.TimeGenerated.minute, event.TimeGenerated.second).strftime(
                        '%d/%m/%Y %H:%M:%S')

                    # print date + ' : ' + log_type + ' -> ' + log_data
                    if data:
                        yield unicode(event.EventCategory), unicode(event.SourceName), unicode(event.EventID), unicode(
                            event.EventType), date, list(data)
                    else:
                        yield unicode(event.EventCategory), unicode(event.SourceName), unicode(event.EventID), unicode(
                            event.EventType), date, []
            if sum_evt >= total:
                break

    def _csv_event_logs(self, is_win_xp):
        """Prints the event logs in a csv, the called method is different for WinXP and lower"""
        server = None  # name of the target computer to get event logs, None to get logs from current computer
        with open(self.output_dir + '\\' + self.computer_name + '_evts' + self.rand_ext, 'wb') as fw:
            csv_writer = get_csv_writer(fw)
            write_to_csv(['COMPUTER', 'TYPE', 'SOURCE', 'CATEGORY', 'SOURCE NAME', 'ID', 'EVENT_TYPE', 'LOG'], csv_writer)
            if is_win_xp:
                for eventCategory, sourceName, eventID, eventType, date, log in self._list_evt_xp(server, 'Security'):
                    write_to_csv([self.computer_name, 'Logs', 'Security', eventCategory, sourceName, eventID, eventType,
                                  date] + log, csv_writer)
                for eventCategory, sourceName, eventID, eventType, date, log in self._list_evt_xp(server,
                                                                                                  'Application'):
                    write_to_csv(
                        [self.computer_name, 'Logs', 'Application', eventCategory, sourceName, eventID, eventType,
                         date] + log, csv_writer)
                for eventCategory, sourceName, eventID, eventType, date, log in self._list_evt_xp(server, 'System'):

# Path: utils/utils.py
# def get_csv_writer(csvfile):
#     return UnicodeWriter(csvfile, quoting=csv.QUOTE_ALL)
# 
# def get_json_writer(json_file):
#     return UnicodeJsonDumper(json_file)
# 
# def write_to_csv(arr_data, csv_writer):
#     """Writes contents to a CSV file using UTF-8"""
#     csv_writer.writerow(arr_data)
# 
# def write_to_json(header, arr_data, json_writer):
#     """Write data in json files using UTF-8"""
#     try:
#         json_writer.dump_json({
#             h: arr_data[index] for index, h in enumerate(header)
#         })
#     except IndexError:
#         json_writer.dump_json({
#             header[index]: d for index, d in enumerate(arr_data)
#         })
# 
# def close_json_writer(json_writer):
#     json_writer.close_current()


# Path: evt/logs.py
import win32evtlog
import datetime
import os
from utils.utils import get_csv_writer, get_json_writer, write_to_csv, write_to_json, close_json_writer

                                             event.TimeGenerated.day, event.TimeGenerated.hour,
                                             event.TimeGenerated.minute, event.TimeGenerated.second).strftime(
                        '%d/%m/%Y %H:%M:%S')

                    # print date + ' : ' + log_type + ' -> ' + log_data
                    if data:
                        yield unicode(event.EventCategory), unicode(event.SourceName), unicode(event.EventID), unicode(
                            event.EventType), date, list(data)
                    else:
                        yield unicode(event.EventCategory), unicode(event.SourceName), unicode(event.EventID), unicode(
                            event.EventType), date, []
            if sum_evt >= total:
                break

    def _csv_event_logs(self, is_win_xp):
        """Prints the event logs in a csv, the called method is different for WinXP and lower"""
        server = None  # name of the target computer to get event logs, None to get logs from current computer
        with open(self.output_dir + '\\' + self.computer_name + '_evts' + self.rand_ext, 'wb') as fw:
            csv_writer = get_csv_writer(fw)
            write_to_csv(['COMPUTER', 'TYPE', 'SOURCE', 'CATEGORY', 'SOURCE NAME', 'ID', 'EVENT_TYPE', 'LOG'], csv_writer)
            if is_win_xp:
                for eventCategory, sourceName, eventID, eventType, date, log in self._list_evt_xp(server, 'Security'):
                    write_to_csv([self.computer_name, 'Logs', 'Security', eventCategory, sourceName, eventID, eventType,
                                  date] + log, csv_writer)
                for eventCategory, sourceName, eventID, eventType, date, log in self._list_evt_xp(server,
                                                                                                  'Application'):
                    write_to_csv(
                        [self.computer_name, 'Logs', 'Application', eventCategory, sourceName, eventID, eventType,
                         date] + log, csv_writer)
                for eventCategory, sourceName, eventID, eventType, date, log in self._list_evt_xp(server, 'System'):

                    write_to_csv([self.computer_name, 'Logs', 'System', eventCategory, sourceName, eventID, eventType,