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")
Exemple #2
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
Exemple #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))
Exemple #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
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
Exemple #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)
    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()