Exemplo n.º 1
0
def filter_session_inbetween_dates(date_one,
                                   date_two,
                                   export_to_csv,
                                   filename=""):
    # ====================
    # Variable declaration
    # ====================
    api = anydesk.API(path="auth.cfg")
    sessions = []
    buffer_start = date_one
    buffer_end = date_two

    if (len(buffer_start) == 10):
        buffer_start += " 00:00:00"

    if (len(buffer_end) == 10):
        buffer_end += " 23:59:59"

    if (filename == ""):
        filename = "../../sessions_inbetween_dates_" + str(
            datetime.now().strftime("%d.%m.%Y_%H-%M-%S")) + ".csv"
    else:
        filename = "../../" + filename + ".csv"

    # Format:                                          (year, month, day, hour, minute, second)
    filter_start_time = datetime.strptime(buffer_start, '%d.%m.%Y %H:%M:%S')
    filter_end_time = datetime.strptime(buffer_end, '%d.%m.%Y %H:%M:%S')

    longest_sessions = api.query_sessions(sort="duration")

    for session in longest_sessions:

        session_start_time = datetime.fromtimestamp(
            time.mktime(time.gmtime(session.start_time)))
        session_end_time = datetime.fromtimestamp(
            time.mktime(time.gmtime(session.end_time)))

        if (session_start_time >= filter_start_time
                and session_end_time <= filter_end_time):

            # Calculate the duration in seconds, minutes, hours and days
            session_id = session.id
            from_ID = session.id_from.id
            from_alias = session.id_from.alias
            to_ID = session.id_to.id
            to_alias = session.id_to.alias
            start_time_session = time.strftime('%Y-%m-%d %H:%M:%S',
                                               time.gmtime(session.start_time))
            end_time_session = time.strftime('%Y-%m-%d %H:%M:%S',
                                             time.gmtime(session.end_time))
            minutes, seconds = divmod(session.duration, 60)
            hours, minutes = divmod(minutes, 60)
            days, hours = divmod(hours, 24)
            comment = session.comment

            if (export_to_csv == "false" or export_to_csv == ""):
                print("\n================\nSession data\n================")
                print("Session ID                = " + str(session_id))
                print("From ID                   = " + str(from_ID))
                print("From Alias                = " + str(from_alias))
                print("To ID                     = " + str(to_ID))
                print("To Alias                  = " + str(to_alias))
                print("Start time                = " + str(start_time_session))
                print("End time                  = " + str(end_time_session))
                print("Days                      = " + str(days))
                print("Hours                     = " + str(hours))
                print("Minutes                   = " + str(minutes))
                print("Seconds                   = " + str(seconds))
                print("Total duration in Seconds = " + str(session.duration))
                print("Comment                   = " + str(comment))
                print("================================\n")

            sessions.append([
                str(session_id),
                str(from_ID),
                str(from_alias),
                str(to_ID),
                str(to_alias),
                str(start_time_session),
                str(end_time_session),
                str(days),
                str(hours),
                str(minutes),
                str(seconds),
                str(session.duration),
                str(comment)
            ])

    if export_to_csv == "true":

        fieldnames = [
            'Session ID', 'From ID', 'From Alias', 'To ID', 'To Alias',
            'Start time', 'End time', 'Days', 'Hours', 'Minutes', 'Seconds',
            'Total duration in Seconds', 'Comment'
        ]

        with open(filename, "w", newline="") as f:

            csv_writer = csv.writer(f)
            csv_writer.writerow(fieldnames)

            for i in range(len(sessions)):
                csv_writer.writerow(sessions[i])

    if (export_to_csv == "true"):
        print(" \n**** Data has been successfully exported to the file \"" +
              str(filename[6:len(filename)]) + "\" ****")
Exemplo n.º 2
0
def filter_session_by_duration_and_count(session_limit,
                                         export_to_csv,
                                         filename=""):
    # ====================
    # Variable declaration
    # ====================
    api = anydesk.API(path="auth.cfg")
    sessions = []

    if (filename == ""):
        filename = "../../sessions_duration_and_count_" + str(
            datetime.now().strftime("%d.%m.%Y_%H-%M-%S")) + ".csv"
    else:
        filename = "../../" + filename + ".csv"

    longest_sessions = api.query_sessions(sort="duration",
                                          limit=int(session_limit))

    for session in longest_sessions:

        # Calculate the duration in seconds, minutes, hours and days
        session_id = session.id
        from_ID = session.id_from.id
        from_alias = session.id_from.alias
        to_ID = session.id_to.id
        to_alias = session.id_to.alias
        start_time_session = time.strftime('%Y-%m-%d %H:%M:%S',
                                           time.gmtime(session.start_time))
        end_time_session = time.strftime('%Y-%m-%d %H:%M:%S',
                                         time.gmtime(session.end_time))
        minutes, seconds = divmod(session.duration, 60)
        hours, minutes = divmod(minutes, 60)
        days, hours = divmod(hours, 24)
        comment = session.comment

        if (export_to_csv == "false" or export_to_csv == ""):
            print("\n================\nSession data\n================")
            print("Session ID                = " + str(session_id))
            print("From ID                   = " + str(from_ID))
            print("From Alias                = " + str(from_alias))
            print("To ID                     = " + str(to_ID))
            print("To Alias                  = " + str(to_alias))
            print("Start time                = " + str(start_time_session))
            print("End time                  = " + str(end_time_session))
            print("Days                      = " + str(days))
            print("Hours                     = " + str(hours))
            print("Minutes                   = " + str(minutes))
            print("Seconds                   = " + str(seconds))
            print("Total duration in Seconds = " + str(session.duration))
            print("Comment                   = " + str(comment))
            print("================================\n")

        sessions.append([
            str(session_id),
            str(from_ID),
            str(from_alias),
            str(to_ID),
            str(to_alias),
            str(start_time_session),
            str(end_time_session),
            str(days),
            str(hours),
            str(minutes),
            str(seconds),
            str(session.duration),
            str(comment)
        ])

    if (export_to_csv == "true"):

        fieldnames = [
            'Session ID', 'From ID', 'From Alias', 'To ID', 'To Alias',
            'Start time', 'End time', 'Days', 'Hours', 'Minutes', 'Seconds',
            'Total duration in Seconds', 'Comment'
        ]

        with open(filename, "w", newline="") as f:

            csv_writer = csv.writer(f)
            csv_writer.writerow(fieldnames)

            for i in range(len(sessions)):
                csv_writer.writerow(sessions[i])

    if (export_to_csv == "true"):
        print(" \n**** Data has been successfully exported to the file \"" +
              str(filename[6:len(filename)]) + "\" ****")
Exemplo n.º 3
0
# --------------
# Library import
# --------------
import sys					# Import the system library
sys.path.append("../../")	# Set the working directory two folder above
import anydesk


# --------------------
# Variable declaration
# --------------------
api = anydesk.API(path="auth.cfg")


with open("sessions.csv", "w", newline="") as f:
	csv = anydesk.SessionCSV(f)
	csv.write(api.all_sessions())

with open("online_clients.csv", "w", newline="") as f:
    csv = anydesk.ClientCSV(f)
    csv.write(api.query_clients(online=True))