forked from hfaran/slack2html
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslack2html.py
More file actions
executable file
·64 lines (51 loc) · 2.2 KB
/
slack2html.py
File metadata and controls
executable file
·64 lines (51 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
import webbrowser
import os
import flask
import click
from slackviewer.app import app
from slackviewer.main import configure_app
from flask_frozen import Freezer
class CustomFreezer(Freezer):
cf_output_dir = None
@property
def root(self):
return u"{}".format(self.cf_output_dir)
@click.command()
@click.option("-z", "--archive", type=click.Path(), required=True,
help="Path to your Slack export archive (.zip file)")
@click.option("-o", "--output-dir", type=click.Path(), required=True,
help="Output directory for HTML files")
@click.option('--channels', type=click.STRING,
help="A comma separated list of channels to parse.")
@click.option('--groups', type=click.STRING,
help="A comma separated list of groups (private channels) to parse.")
@click.option('--exclude-dms', is_flag=True,
default=False,
help="Exclude DMs from parsing.")
@click.option('--exclude-mpims', is_flag=True,
default=False,
help="Exclude multiple users DMs from parsing.")
@click.option('--no-browser', is_flag=True,
help="If you do not want a browser to open "
"automatically, set this.")
@click.option('--debug', is_flag=True)
def main(archive, output_dir, channels, groups, exclude_dms, exclude_mpims, no_browser, debug):
configure_app(app=app, archive=archive, channels=channels, groups=groups, exclude_dms=exclude_dms, exclude_mpims=exclude_mpims, no_sidebar=False, no_external_references=False, debug=debug)
# We need relative URLs, otherwise channel refs do not work
app.config["FREEZER_RELATIVE_URLS"] = True
# Use a custom subclass of Freezer which allows to overwrite
# the output directory
freezer = CustomFreezer(app)
freezer.cf_output_dir = output_dir
# This tells freezer about the channel URLs
@freezer.register_generator
def channel_name():
for channel in flask._app_ctx_stack.channels:
yield {"name": channel}
freezer.freeze()
if not no_browser:
webbrowser.open("file:///{}/index.html"
.format(os.path.abspath(output_dir)))
if __name__ == '__main__':
main()