Skip to content

Commit

Permalink
Add option to provide a template when exporting via the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
volker-fr committed Dec 31, 2024
1 parent 78b5936 commit 8f29c3f
Show file tree
Hide file tree
Showing 3 changed files with 424 additions and 10 deletions.
58 changes: 49 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion slackviewer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 8f29c3f

Please sign in to comment.