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")
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 + "/channel", user_data, channel_data) private_channels = compile_channels(path + "/private_channels", user_data, channel_data) dms = compile_channels(path + "/direct_message", user_data, channel_data) top = flask._app_ctx_stack top.channels = channels top.private_channels = private_channels top.dms = dms
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) # 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()