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
966 stars 193 forks source link

Ensure Compatibility with flask_frozen v1.0.1 #182

Closed greymd closed 10 months ago

greymd commented 10 months ago

This commit addresses an AttributeError encountered when using flask_frozen v1.0.1 with CustomFreezer class. Previously, the CustomFreezer's root property was returning a string representation of the cf_output_dir, which caused compatibility issues with the latest version of flask_frozen.

This update resolves the AttributeError ('str' object has no attribute 'mkdir') and ensures our CustomFreezer class works seamlessly with flask_frozen v1.0.1.

The error resolved by this change:

$ python3 app.py --channels test_channel -z test_dir --html-only -o output
Traceback (most recent call last):
  File "/Users/greymd/repos/hfaran/slack-export-viewer/app.py", line 6, in <module>
    main()
  File "/Users/greymd/repos/hfaran/slack-export-viewer/venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/greymd/repos/hfaran/slack-export-viewer/venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/greymd/repos/hfaran/slack-export-viewer/venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/greymd/repos/hfaran/slack-export-viewer/venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/greymd/repos/hfaran/slack-export-viewer/slackviewer/main.py", line 95, in main
    freezer.freeze()
  File "/Users/greymd/repos/hfaran/slack-export-viewer/venv/lib/python3.11/site-packages/flask_frozen/__init__.py", line 179, in freeze
    return set(page.url for page in self.freeze_yield())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/greymd/repos/hfaran/slack-export-viewer/venv/lib/python3.11/site-packages/flask_frozen/__init__.py", line 179, in <genexpr>
    return set(page.url for page in self.freeze_yield())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/greymd/repos/hfaran/slack-export-viewer/venv/lib/python3.11/site-packages/flask_frozen/__init__.py", line 150, in freeze_yield
    self.root.mkdir(parents=True, exist_ok=True)
    ^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'mkdir'
nathang21 commented 10 months ago

Thanks for putting this together, i'm experiencing this in #181, however from a quick test i'm still running into the exact same error. Happy to help debug this PR if you need more information, or I can keep the discussion on the issue.

➜  slack-export-viewer git:(greymd/master) gh pr checkout 182 && git reset --hard
➜  slack-export-viewer git:(greymd/master) slack-export-viewer -z export.zip -p 5001 --debug --html-only
WARNING: DEBUG MODE IS ENABLED!
/var/folders/2h/rxc9f0qd5tg0qy595fzcc9zm0000gp/T/_slackviewer/9de4c73f97cfab33209489aa3663ad2fe558f973 already exists
Traceback (most recent call last):
  File "/usr/local/bin/slack-export-viewer", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/slackviewer/main.py", line 95, in main
    freezer.freeze()
  File "/usr/local/lib/python3.11/site-packages/flask_frozen/__init__.py", line 179, in freeze
    return set(page.url for page in self.freeze_yield())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flask_frozen/__init__.py", line 179, in <genexpr>
    return set(page.url for page in self.freeze_yield())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flask_frozen/__init__.py", line 150, in freeze_yield
    self.root.mkdir(parents=True, exist_ok=True)
    ^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'mkdir'
greymd commented 10 months ago

@nathang21 I apologize if I'm mistaken, but it seems like you may not be using the slack-export-viewer with the changes I've made. How about trying the following steps?

$ gh pr checkout 182 && git reset --hard
$ pip3 install -r requirements.txt
$ pip3 install -e .
$ slack-export-viewer -z export.zip -p 5001 --debug --html-only
nathang21 commented 10 months ago

@greymd Oops, pip3 install -e . was the piece I was missing, not as familiar with pip as I should be. Thanks for the reply!

thejoecarroll commented 10 months ago

How soon before this PR is likely to make it into a release? It seems that it would fix an issue I reported, #181 , about being unable to output static HTML, which is important for me.