diff --git a/README.md b/README.md index f967360..7a4832a 100644 --- a/README.md +++ b/README.md @@ -92,33 +92,73 @@ slack-export-viewer -z /path/to/export/zip If everything went well, your archive will have been extracted and processed, and a browser window will have opened showing your *#general* channel from the export. Or, if the `html-only` flag was set, HTML files will be available in the `html-output` directory (or a different directory if specified). + ## CLI There is now a CLI included as well. Currently the one command you can use is clearing the cache from slack-export-viewer from your %TEMP% directory; see usage: -``` -└———→ slack-export-viewer-cli --help -Usage: slack-export-viewer-cli [OPTIONS] COMMAND [ARGS]... +```bash +$ slack-export-viewer-cli --help +Usage: cli.py [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. Commands: - clean Cleans up any temporary files (including... + clean Cleans up any temporary files (including cached output by... export Generates a single-file printable export for an archive file or... ``` -### Examples +Export: +```bash +$ slack-export-viewer-cli export --help +Usage: cli.py export [OPTIONS] ARCHIVE_DIR + + Generates a single-file printable export for an archive file or directory +Options: + --debug + --since [%Y-%m-%d] Only show messages since this date. + --template FILENAME Custom single file export template + --help Show this message and exit. ``` -┌— hamza@AURORAONE C:\Users\hamza -└———→ slack-export-viewer-cli clean +An example template can be found in the repositories [`slackviewer/templates/example_template_single_export.html`](https://github.com/hfaran/slack-export-viewer/tree/master/slackviewer/templates/example_template_single_export.html) file + +Clean +```bash +$ slack-export-viewer-cli clean --help +Usage: cli.py clean [OPTIONS] + + Cleans up any temporary files (including cached output by slack-export- + viewer) + +Options: + -w, --wet Actually performs file deletion + --help Show this message and exit. +``` + + +### Examples + +Clean: +```bash +$ slack-export-viewer-cli clean Run with -w to remove C:\Users\hamza\AppData\Local\Temp\_slackviewer -┌— hamza@AURORAONE C:\Users\hamza -└———→ slack-export-viewer-cli clean -w +$ slack-export-viewer-cli clean -w Removing C:\Users\hamza\AppData\Local\Temp\_slackviewer... ``` +Export: +```bash +$ slack-export-viewer-cli export \ + --since $(date -d "2 days ago" '+%Y-%m-%d') \ + --template /tmp/example_template_single_export.html \ + /tmp/slack-export +Archive already extracted. Viewing from /tmp/slack-export... +Exported to slack-export.html +``` + + ## Local Development After installing the requirements in requirements.txt and dev-requirements.txt, diff --git a/slackviewer/cli.py b/slackviewer/cli.py index 47d99fe..95853b6 100644 --- a/slackviewer/cli.py +++ b/slackviewer/cli.py @@ -36,11 +36,15 @@ def clean(wet): @click.option('--debug', is_flag=True, default=flag_ennvar("FLASK_DEBUG")) @click.option("--since", default=None, type=click.DateTime(formats=["%Y-%m-%d"]), help="Only show messages since this date.") +@click.option("--template", default=None, type=click.File('r'), help="Custom single file export template") @click.argument('archive_dir') -def export(archive_dir, debug, since): +def export(archive_dir, debug, since, template): css = pkgutil.get_data('slackviewer', 'static/viewer.css').decode('utf-8') + tmpl = Environment(loader=PackageLoader('slackviewer')).get_template("export_single.html") + if template: + tmpl = Environment(loader=PackageLoader('slackviewer')).from_string(template.read()) export_file_info = get_export_info(archive_dir) r = Reader(export_file_info["readable_path"], debug, since) channel_list = sorted( diff --git a/slackviewer/templates/example_template_single_export.html b/slackviewer/templates/example_template_single_export.html new file mode 100644 index 0000000..71db639 --- /dev/null +++ b/slackviewer/templates/example_template_single_export.html @@ -0,0 +1,370 @@ +{% macro render_thumbnail(parent, thumbnail_size=None, no_external_references=False) -%} + {% set thumb = parent.thumbnail(thumbnail_size) %} + {% if not no_external_references and thumb %} + + + + {% else %} + + {% endif %} +{%- endmacro %} + +{% macro render_message(message, preview_size=None, no_external_references=False) -%} +
+
+ {% if not message.is_recent_msg %} +
+ {% endif %} + {% if not message.is_thread_msg %} +
+ {% else %} +
+ {% endif %} + {% if not no_external_references and not message.is_thread_msg %} + {% if message.img %}{%else%}
{%endif%} + {% elif not no_external_references and message.is_thread_msg %} + {% if message.img %}{%else%}
{%endif%} + {% endif %} +
{{ message.username }} + {%if message.user.email%} ({{message.user.email}}){%endif%} +
+
{{ message.time }}
+
+ {{ message.msg|safe }} + {% for attachment in message.attachments -%} +
+ {%if attachment.service_name %}
{{ attachment.service_name }}
{%endif%} + {%if attachment.author_name%} +
+ {% if not no_external_references %} + + {% endif %} + {%if attachment.author_link%}{%endif%} + {{attachment.author_name}} + {%if attachment.author_link%}({{attachment.author_link}}){%endif%} +
+ {%endif%} + {% if not no_external_references %} + {%if attachment.pretext %}
{{attachment.pretext}}
{%endif%} + + + {%for field in attachment.fields %} +
+ {%if field.title %}
{{field.title}}
{%endif%} + {{field.value}} +
+ {%endfor%} + {{ render_thumbnail(attachment, preview_size) }} + {% if attachment.original_url %} + + {% endif %} + {%if attachment.footer%} + + {%endif%} + {%endif%} +
+ {% endfor %} + {% for file in message.files -%} +
+ + {% if not no_external_references %} + {{ render_thumbnail(file, preview_size) }} + {%endif%} +
+ {% endfor %} + {% for reaction in message.reactions %} +
+ {{ reaction.name }} {{ reaction.usernames|join(', ') }} +
+ {% endfor %} +
+
+
+
+{%- endmacro %} + + + + + Slack Export - {{ workspace_name }} + + + +

TEMPLATE Export of Slack Workspace "{{workspace_name}}"

+ + + + +
+ {% for channel in channels %} +
+

Messages in #{{channel.channel_name}}

+
+ {% for message in channel.messages %} + {{render_message(message)}} + {% endfor %} +
+
+ {% endfor %} + +