builder.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. from os.path import join as joinpath
  2. from json import load
  3. from os import mkdir
  4. from shutil import rmtree as rmdir
  5. SITES_DIRECTORY = "sites"
  6. USE_FILETYPE = "xhtml"
  7. SITES: dict[str, dict] = {}
  8. with open("users.json") as file:
  9. SITES = load(file)
  10. # Below is XHTML because it is
  11. BringUserToSite = """
  12. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  13. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  14. <html xmlns="http://www.w3.org/1999/xhtml">
  15. <head>
  16. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  17. <meta http-equiv="refresh" content="0; url={{siteurl}}" />
  18. <link rel="canonical" href="{{siteurl}}" />
  19. <title>Bringing you to {{siteid}}</title>
  20. <style type="text/css">
  21. /*<![CDATA[*/
  22. html {
  23. background-color: #000;
  24. color: #fff;
  25. }
  26. a {
  27. color: #0af;
  28. text-decoration: underline;
  29. }
  30. /*]]>*/
  31. </style>
  32. </head>
  33. <body>
  34. <h1>Bringing You Somewhere Else...</h1>
  35. <p>
  36. Uh-Oh! If you're seeing this, the page has failed to
  37. bring you to <a href="{{siteurl}}">{{siteid}}</a>'(s)
  38. site!
  39. </p>
  40. <p>
  41. To be taken there, use the following URL:
  42. </p>
  43. <p>
  44. <a href="{{siteurl}}">{{siteurl}}</a>
  45. </p>
  46. <script type="application/javascript">
  47. //<![CDATA[
  48. if (window && window.location && window.location.replace) {
  49. window.location.replace("{{siteurl}}");
  50. } else if (window && window.location) {
  51. windows.location = "{{siteurl}}";
  52. }
  53. //]]>
  54. </script>
  55. <!--
  56. This all _should_ work in basically
  57. every browser and search crawler that
  58. has ever existed.
  59. -->
  60. </body>
  61. </html>
  62. """
  63. def main():
  64. try:
  65. rmdir(SITES_DIRECTORY)
  66. print("Reinitalizing sites directory")
  67. except:
  68. print("Creating sites directory")
  69. mkdir(SITES_DIRECTORY)
  70. for index, cursite in enumerate(SITES):
  71. print("Creating site directory for %s" % cursite["id"])
  72. maker = lambda site: BringUserToSite.replace("{{siteid}}", site["id"]).replace("{{siteurl}}", site["url"])
  73. NextIndex = index + 1 if index + 1 < len(SITES) else 0
  74. PrevIndex = index - 1 if index - 1 > 0 else len(SITES) - 1
  75. Next = maker(SITES[NextIndex])
  76. Prev = maker(SITES[PrevIndex])
  77. mkdir(joinpath(SITES_DIRECTORY, cursite["id"]))
  78. with open(joinpath(SITES_DIRECTORY, cursite["id"], "next.%s" % USE_FILETYPE), "x") as file:
  79. file.write(Next)
  80. with open(joinpath(SITES_DIRECTORY, cursite["id"], "prev.%s" % USE_FILETYPE), "x") as file:
  81. file.write(Prev)
  82. print("Finished making sites directory")
  83. if __name__ == "__main__":
  84. main()