Example #1
0
def configure_app(app, archive, debug):
    app.debug = debug
    if app.debug:
        print("WARNING: DEBUG MODE IS ENABLED!")
    app.config["PROPAGATE_EXCEPTIONS"] = True

    path = extract_archive(archive)

    empty_dms = get_empty_dm_names(path)

    user_data = get_users(path)
    channel_data = get_channels(path)
    group_data = get_groups(path)
    dm_data = get_dms(path)
    mpim_data = get_mpims(path)

    channels = compile_channels(path, user_data, channel_data)
    groups = compile_groups(path, user_data, group_data)
    dms = compile_dms(path, user_data, dm_data)
    dm_users = compile_dm_users(path, user_data, dm_data, empty_dms)
    mpims = compile_mpims(path, user_data, dm_data)
    mpim_users = compile_mpim_users(path, user_data, mpim_data)

    top = flask._app_ctx_stack
    top.channels = channels
    top.groups = groups
    top.dms = dms
    top.dm_users = dm_users
    top.mpims = mpims
    top.mpim_users = mpim_users
def main(archive, destination):
    if not archive:
        raise ValueError("Empty path provided for archive")

    arch_path = extract_archive(archive)
    user_data = get_users(arch_path)
    channel_data = get_channels(arch_path)
    channels = compile_channels(arch_path, user_data, channel_data)

    path = os.path.join(os.path.split(arch_path)[0], 'archive-webview')
    if destination:
        path = destination

    if not os.path.isdir(path):
        os.makedirs(path)
    css_src = os.path.join(slackviewer.__path__[0], "templates/viewer.css")
    css_des = os.path.join(path, 'viewer.css')
    shutil.copy2(css_src, css_des)

    env = Environment(loader=PackageLoader('slackviewer', 'templates'),
                      autoescape=select_autoescape(['html', 'xml']))
    template = env.get_template('viewer.html')
    for name in sorted(channels):
        page = template.render(messages=channels[name],
                               channels=sorted(channels.keys()),
                               name=name)
        channel_file = "{}.html".format(os.path.join(path, name))
        with open(channel_file, "w") as file:
            file.write(page.encode('ascii', 'ignore'))
    print("Finished creating web files for archive")
Example #3
0
def main(port, archive, ip, no_browser, test, debug):
    if not archive:
        raise ValueError("Empty path provided for archive")

    configure_app(app, archive, debug)

    if not no_browser and not test:
        webbrowser.open("http://{}:{}".format(ip, port))

    if not test:
        app.run(host=ip, port=port)

    #download code

    avatar_dir = "avatars"
    if not os.path.exists(avatar_dir):
        os.makedirs(avatar_dir)

    path = extract_archive(archive)

    users = get_users(path)

    sizes = ["24", "32", "48", "72", "192", "512"]
    for size in sizes:
        if not os.path.exists(os.path.join(avatar_dir, size)):
            os.makedirs(os.path.join(avatar_dir, size))

        for user in users:
            url = ""
            if "image_{}".format(size) in users[user]["profile"].keys():
                url = users[user]["profile"]["image_{}".format(size)]
            if url != "":
                filename, file_extension = os.path.splitext(url)
                file_to_save = os.path.join(
                    avatar_dir, size, "{}_{}{}".format(user, size,
                                                       file_extension))
                if not os.path.exists(file_to_save):
                    urllib.request.urlretrieve(url, file_to_save)
                    print("{} {}".format(size, user))

    app1 = flask.Flask(__name__,
                       template_folder="templates",
                       static_folder="static")
    app1.config["SERVER_NAME"] = "test"
    names = ["thelunchers", "secure4questions4dev"]
    channels = get_channels(path)
    for channel_id in channels:
        name = channels[channel_id]["name"]
        #if name == "hadoop":
        #    continue
        print("CHANNEL: {}".format(name))
        with app1.app_context():
            with open("{}.aspx".format(name), 'w', encoding="utf-8") as file:
                file.write(channel_name(name))
Example #4
0
def configure_app(app, archive, debug):
    app.debug = debug
    if app.debug:
        print("WARNING: DEBUG MODE IS ENABLED!")
    app.config["PROPAGATE_EXCEPTIONS"] = True

    path = extract_archive(archive)
    user_data = get_users(path)
    channel_data = get_channels(path)
    channels = compile_channels(path, user_data, channel_data)

    top = flask._app_ctx_stack
    top.channels = channels
Example #5
0
def configure_app(app, archive, debug):
    app.debug = debug
    if app.debug:
        print("WARNING: DEBUG MODE IS ENABLED!")
    app.config["PROPAGATE_EXCEPTIONS"] = True

    path = extract_archive(archive)
    user_data = get_users(path)
    channel_data = get_channels(path)
    channels = compile_channels(path, user_data, channel_data)

    top = flask._app_ctx_stack
    top.channels = channels
Example #6
0
def configure_app(app, archive, debug):
    app.debug = debug
    if app.debug:
        print("WARNING: DEBUG MODE IS ENABLED!")
    app.config["PROPAGATE_EXCEPTIONS"] = True

    path = extract_archive(archive)
    reader = Reader(path)

    top = flask._app_ctx_stack
    top.channels = reader.compile_channels()
    top.groups = reader.compile_groups()
    top.dms = reader.compile_dm_messages()
    top.dm_users = reader.compile_dm_users()
    top.mpims = reader.compile_mpim_messages()
    top.mpim_users = reader.compile_mpim_users()
Example #7
0
def configure_app(app, archive, channels, no_sidebar, no_external_references, debug):
    app.debug = debug
    app.no_sidebar = no_sidebar
    app.no_external_references = no_external_references
    if app.debug:
        print("WARNING: DEBUG MODE IS ENABLED!")
    app.config["PROPAGATE_EXCEPTIONS"] = True

    path = extract_archive(archive)
    reader = Reader(path)

    top = flask._app_ctx_stack
    top.channels = reader.compile_channels(channels)
    top.groups = reader.compile_groups()
    top.dms = reader.compile_dm_messages()
    top.dm_users = reader.compile_dm_users()
    top.mpims = reader.compile_mpim_messages()
    top.mpim_users = reader.compile_mpim_users()
Example #8
0
def configure_app(app, archive, channels, no_sidebar, no_external_references,
                  debug):
    app.debug = debug
    app.no_sidebar = no_sidebar
    app.no_external_references = no_external_references
    if app.debug:
        print("WARNING: DEBUG MODE IS ENABLED!")
    app.config["PROPAGATE_EXCEPTIONS"] = True

    path = extract_archive(archive)
    reader = Reader(path)

    top = flask._app_ctx_stack
    top.channels = reader.compile_channels(channels)
    top.groups = reader.compile_groups()
    top.dms = reader.compile_dm_messages()
    top.dm_users = reader.compile_dm_users()
    top.mpims = reader.compile_mpim_messages()
    top.mpim_users = reader.compile_mpim_users()
    top.root_dir = path
Example #9
0
def configure_app(app, archive, channels, no_sidebar, no_external_references,
                  debug, meilisearch_host, meilisearch_master_key):
    app.debug = debug
    app.no_sidebar = no_sidebar
    app.no_external_references = no_external_references
    if app.debug:
        print("WARNING: DEBUG MODE IS ENABLED!")
    app.config["PROPAGATE_EXCEPTIONS"] = True

    path = extract_archive(archive)
    reader = Reader(path)

    top = flask._app_ctx_stack
    top.channels = reader.compile_channels(channels)
    top.groups = reader.compile_groups()
    top.dms = reader.compile_dm_messages()
    top.dm_users = reader.compile_dm_users()
    top.mpims = reader.compile_mpim_messages()
    top.mpim_users = reader.compile_mpim_users()
    top.meilisearch_host = meilisearch_host
    top.meilisearch_master_key = meilisearch_master_key

    message_channel_index = {}
    for channelname in top.channels.keys():
        for index, message in enumerate(top.channels[channelname]):
            if message.client_msg_id is None:
                continue
            message_channel_index[message.client_msg_id] = (channelname, index)

    message_group_index = {}
    for groupname in top.groups.keys():
        for index, message in enumerate(top.groups[groupname]):
            if message.client_msg_id is None:
                continue
            message_group_index[message.client_msg_id] = (groupname, index)

    top.message_channel_index = message_channel_index
    top.message_group_index = message_group_index
Example #10
0
def configure_app(app, archive, debug):
    app.debug = debug
    if app.debug:
        print("WARNING: DEBUG MODE IS ENABLED!")
    app.config["PROPAGATE_EXCEPTIONS"] = True

    path = extract_archive(archive)
    user_data = get_users(path)
    channel_data = get_channels(path)
    channels = compile_channels(path, user_data, channel_data)
    # Creat our cover
    create_cover(channels)
    #
    # RUN TEAM ANALYSIS
    top = flask._app_ctx_stack
    top.channels = channels
    print(type(channels))
    usernames = []
    timestamps = []
    channel_popularity = dict()
    user_num_words = dict()
    for ch_id, messages in channels.items():
        channel_popularity[ch_id] = len(messages)
        for message in messages:
            if message.username in user_num_words and not message.username.isupper(
            ):
                user_num_words[message.username] += len(message.msg.split())
            elif not message.username.isupper():
                user_num_words[message.username] = len(message.msg.split())
            usernames.append(message.username)
            timestamps.append(
                datetime.datetime.strptime(message.time, "%Y-%m-%d %H:%M:%S"))

    # Get num messages per user in descending order
    count_users = {
        k: v
        for k, v in Counter(usernames).items() if not k.isupper()
    }
    count_date_of_message = Counter([t.date() for t in timestamps])
    count_hour_of_message = OrderedDict()
    for k, v in Counter([t.hour for t in timestamps]).items():
        count_hour_of_message[str(k + 1) + ':00'] = v

    # TODO get number of words written by user
    # TODO get ave length of message by user

    pp = PdfPages('report_src/report_graphs.pdf')
    # plot the graphs
    plot1 = plotGraph_fromDict(count_users, "Most Messages")
    plot2 = plotGraph_fromDict(count_date_of_message, "Posts Per Day")
    plot3 = plotGraph_fromDict(count_hour_of_message,
                               "Most Frequent Posting Hours")
    plot4 = plotGraph_fromDict(user_num_words,
                               "Number of words written per user")
    plot5 = plotGraph_fromDict(channel_popularity,
                               "Channel Popularity By Number of Messages")
    pp.savefig(plot1)
    pp.savefig(plot2)
    pp.savefig(plot3)
    pp.savefig(plot4)
    pp.savefig(plot5)
    pp.close()
Example #11
0
from slackviewer.app import app as application
from slackviewer.archive import extract_archive
from slackviewer.reader import Reader
from slackviewer.appconfig import set_env_params

import os

try:
    from flask import _app_ctx_stack as stack
except ImportError:
    from flask import _request_ctx_stack as stack

set_env_params()

path = extract_archive(os.environ.get("SEV_ARCHIVE"))
reader = Reader(path)
stack.channels = reader.compile_channels(os.environ.get("SEV_CHANNELS", None))
stack.groups = reader.compile_groups()
stack.dms = reader.compile_dm_messages()
stack.dm_users = reader.compile_dm_users()
stack.mpims = reader.compile_mpim_messages()
stack.mpim_users = reader.compile_mpim_users()

if __name__ == '__main__':
    if not application.is_test:
        application.run(host=os.environ.get("SEV_IP", '0.0.0.0'),
                        port=os.environ.get("SEV_PORT", 5000))