i am le epic gay
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

144 wiersze
6.2KB

  1. #!/usr/bin/python3
  2. # made by Vane Vander <https://mayvaneday.keybase.pub>
  3. # this is version 0.1.0, last edited on 4 February 2019
  4. # hey look it's skyworld!
  5. # implemented:
  6. # - going places
  7. # - exiting
  8. # - parsing info and directory lines in gophermaps
  9. # - parsing HTML and plaintext lines in gophermaps
  10. # - parsing TXT and MD files
  11. # - displaying the current URL
  12. # - quickly getting back to the root of a website
  13. # - 404 errors when a document is not found
  14. # - quick browsing for directories in Gophernicus
  15. # to implement next:
  16. # - quick browsing for files
  17. # - formatting HTML files properly
  18. # - nicer URLs
  19. # - going back one URL in history
  20. # - history, for that matter
  21. import os
  22. import time
  23. url = ""
  24. while True:
  25. pygopherdException = False
  26. if url is "":
  27. url = input("yo where tf do you wanna go? ")
  28. if url is "exit":
  29. os.system("clear")
  30. break
  31. else:
  32. addurl = input("yo where tf do you wanna go next? ")
  33. if addurl == "exit" or addurl == "quit" or addurl == "leave":
  34. os.system("clear")
  35. break
  36. elif addurl == "home":
  37. wholeURL = url.split("/")
  38. homeURL = wholeURL[0]
  39. url = homeURL
  40. elif addurl == "elsewhere":
  41. url = ""
  42. elif addurl.isdigit():
  43. numerator = int(addurl) - 1
  44. wholeURL = url.split("/")
  45. homeURL = wholeURL[0]
  46. url = homeURL
  47. try:
  48. url = url + "/1/" + directories[numerator] # this breaks with pygopherd
  49. except: # catch pygopherd exception
  50. pygopherdException = True
  51. print("Error: Quick browsing isn't implemented with pygopherd yet.")
  52. time.sleep(2)
  53. directores = []
  54. elif addurl is not "elsewhere":
  55. url = url + addurl
  56. content = os.popen("curl -s gopher://" + url).readlines()
  57. if len(content) == 0 and url is not "":
  58. print("404 not found")
  59. elif url is not "":
  60. os.system("clear")
  61. if url[-2] == "m" or url[-2] == "x": # parsing HTML/Markdown/text files (hacky workaround; will almost always break)
  62. print(" ")
  63. for i in content:
  64. newLineFix = i.rstrip()
  65. print(newLineFix)
  66. print(" ")
  67. print("URL: gopher://" + str(url))
  68. print(" ")
  69. else:
  70. acc = 0
  71. directories = []
  72. for i in content:
  73. newLineFix = i.rstrip()
  74. if newLineFix[0] == "i": # parsing info lines
  75. if "null.host" in i: # for Gophernicus
  76. info = newLineFix[1:].split("null.host")
  77. print(info[0])
  78. elif "(NULL)" in i: # for pygopherd
  79. info = newLineFix[1:].split("(NULL)")
  80. info2 = info[0]
  81. print(info2[:-5])
  82. elif newLineFix[0] == "1": # parsing directory lines
  83. if newLineFix[-1] == "+": # for pygopherd
  84. info = newLineFix[1:].split()
  85. directory = info[-4]
  86. directoryNameList = []
  87. for i in range(len(info)):
  88. directoryNameList.append(info[i])
  89. for i in range(4):
  90. del directoryNameList[-1]
  91. directoryName = ""
  92. for i in directoryNameList:
  93. directoryName = directoryName + i + " "
  94. acc = acc + 1
  95. print("(" + str(acc) + ") (DIR) " + directoryName + ": /1" + directory)
  96. else: # for Gophernicus (NEEDS FIXING)
  97. info = newLineFix[1:].split()
  98. directory = info[-3]
  99. directoryNameList = []
  100. for i in range(len(info)):
  101. directoryNameList.append(info[i])
  102. for i in range(2):
  103. del directoryNameList[-1]
  104. directoryName = ""
  105. for i in directoryNameList:
  106. if i[-1] == "/": # hack to get rid of trailing slash on tildeverse directory names
  107. i = i[:-1]
  108. directoryName = i[1:] + " "
  109. acc = acc + 1
  110. directories.append(directory)
  111. print("(" + str(acc) + ") (DIR) " + directoryName + ": /1" + directory)
  112. elif newLineFix[0] == "0" or newLineFix[0] == "h": # parsing links to text/HTML files
  113. if newLineFix[-1] == "+": # for pygopherd
  114. info = newLineFix[1:].split()
  115. directory = info[-4]
  116. directoryNameList = []
  117. for i in range(len(info)):
  118. directoryNameList.append(info[i])
  119. for i in range(4):
  120. del directoryNameList[-1]
  121. directoryName = ""
  122. for i in directoryNameList:
  123. directoryName = directoryName + i + " "
  124. print("(TEXT) " + directoryName + ": /1" + directory)
  125. else: # for Gophernicus
  126. info = newLineFix[1:].split()
  127. directory = info[-3]
  128. directoryNameList = []
  129. for i in range(len(info)):
  130. directoryNameList.append(info[i])
  131. #for i in range(3):
  132. # del directoryNameList[-1]
  133. directoryName = ""
  134. for i in directoryNameList:
  135. if i[-1] == "/": # hack to get rid of trailing slash on tildeverse directory names
  136. i = i[:-1]
  137. directoryName = i[2:] + " "
  138. print("(TEXT) /1" + directory) # this is broken as hell (no formatted file names) but I don't care right now
  139. print(" ")
  140. print(" ")
  141. print("URL: gopher://" + str(url))
  142. print(" ")