app.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import flask
  2. app = flask.Flask(
  3. __name__,
  4. template_folder="templates",
  5. static_folder="static"
  6. )
  7. @app.route("/channel/<name>/")
  8. def channel_name(name):
  9. messages = flask._app_ctx_stack.channels[name]
  10. channels = list(flask._app_ctx_stack.channels.keys())
  11. groups = list(flask._app_ctx_stack.groups.keys()) if flask._app_ctx_stack.groups else {}
  12. dm_users = list(flask._app_ctx_stack.dm_users)
  13. mpim_users = list(flask._app_ctx_stack.mpim_users)
  14. return flask.render_template("viewer.html", messages=messages,
  15. name=name.format(name=name),
  16. channels=sorted(channels),
  17. groups=sorted(groups) if groups else {},
  18. dm_users=dm_users,
  19. mpim_users=mpim_users,
  20. no_sidebar=app.no_sidebar,
  21. no_external_references=app.no_external_references)
  22. @app.route("/group/<name>/")
  23. def group_name(name):
  24. messages = flask._app_ctx_stack.groups[name]
  25. channels = list(flask._app_ctx_stack.channels.keys())
  26. groups = list(flask._app_ctx_stack.groups.keys())
  27. dm_users = list(flask._app_ctx_stack.dm_users)
  28. mpim_users = list(flask._app_ctx_stack.mpim_users)
  29. return flask.render_template("viewer.html", messages=messages,
  30. name=name.format(name=name),
  31. channels=sorted(channels),
  32. groups=sorted(groups),
  33. dm_users=dm_users,
  34. mpim_users=mpim_users,
  35. no_sidebar=app.no_sidebar,
  36. no_external_references=app.no_external_references)
  37. @app.route("/dm/<id>/")
  38. def dm_id(id):
  39. messages = flask._app_ctx_stack.dms[id]
  40. channels = list(flask._app_ctx_stack.channels.keys())
  41. groups = list(flask._app_ctx_stack.groups.keys())
  42. dm_users = list(flask._app_ctx_stack.dm_users)
  43. mpim_users = list(flask._app_ctx_stack.mpim_users)
  44. return flask.render_template("viewer.html", messages=messages,
  45. id=id.format(id=id),
  46. channels=sorted(channels),
  47. groups=sorted(groups),
  48. dm_users=dm_users,
  49. mpim_users=mpim_users,
  50. no_sidebar=app.no_sidebar,
  51. no_external_references=app.no_external_references)
  52. @app.route("/mpim/<name>/")
  53. def mpim_name(name):
  54. messages = flask._app_ctx_stack.mpims.get(name, list())
  55. channels = list(flask._app_ctx_stack.channels.keys())
  56. groups = list(flask._app_ctx_stack.groups.keys())
  57. dm_users = list(flask._app_ctx_stack.dm_users)
  58. mpim_users = list(flask._app_ctx_stack.mpim_users)
  59. return flask.render_template("viewer.html", messages=messages,
  60. name=name.format(name=name),
  61. channels=sorted(channels),
  62. groups=sorted(groups),
  63. dm_users=dm_users,
  64. mpim_users=mpim_users,
  65. no_sidebar=app.no_sidebar,
  66. no_external_references=app.no_external_references)
  67. @app.route("/")
  68. def index():
  69. channels = list(flask._app_ctx_stack.channels.keys())
  70. groups = list(flask._app_ctx_stack.groups.keys())
  71. dms = list(flask._app_ctx_stack.dms.keys())
  72. mpims = list(flask._app_ctx_stack.mpims.keys())
  73. if channels:
  74. if "general" in channels:
  75. return channel_name("general")
  76. else:
  77. return channel_name(channels[0])
  78. elif groups:
  79. return group_name(groups[0])
  80. elif dms:
  81. return dm_id(dms[0])
  82. elif mpims:
  83. return mpim_name(mpims[0])
  84. else:
  85. return "No content was found in your export that we could render."