hfaran / slack-export-viewer

A Slack Export archive viewer that allows you to easily view and share your Slack team's export
https://pypi.python.org/pypi/slack-export-viewer
MIT License
908 stars 192 forks source link

Error when a channel is empty #105

Closed bblising closed 4 years ago

bblising commented 5 years ago

We are on on a free subscription and we've long forgotten whether we used the default Random and General channels. They are empty after using https://github.com/zach-snell/slack-export and this causes an exception to the lines

    if "general" in channels:
        return channel_name("general")
    else:
        return channel_name(channels[0])

in app.py. The workaround I did is to wrap this in an exception and return the first DM instead.

hfaran commented 4 years ago

What's the exception that is thrown?

asmaier commented 4 years ago

I ran into the same issue. It happens if you are using https://github.com/zach-snell/slack-export , but don't export the public channels. The exception is

File "...slack-export/env_slack-export/lib/python3.6/site-packages/slackviewer/app.py", line 89, in index
     return channel_name(channels[0])
 IndexError: list index out of range
chopley commented 4 years ago

This is a problem when no public channels are requested in the export. This can be handled by adding other messages types possible from https://github.com/zach-snell/slack-export e.g. private groups, DMS etc.. A suggested start for bug correction is below ..packages/slackviewer/app.py

@app.route("/")
def index():
    channels = list(flask._app_ctx_stack.channels.keys())
    groups = list(flask._app_ctx_stack.groups.keys())
    dm_users = list(flask._app_ctx_stack.dm_users)
    mpim_users = list(flask._app_ctx_stack.mpim_users)
    if(len(channels) > 0):
        if "general" in channels:
            return channel_name("general")
        else:
            return channel_name(channels[0])
    elif(len(groups) >0):
        return(group_name(groups[0]))
    elif(len(dm_users) >0):
        return(dm_id(dm_users[0]))
    else:
        print("Not sure where to start- Try adding a Private group, Public group or DM to the slack-export ")
hfaran commented 4 years ago

Release 1.0.1 published