gopherhole/software/skyworld
2019-03-27 02:55:34 +00:00

144 lines
6.2 KiB
Python

#!/usr/bin/python3
# made by Vane Vander <https://mayvaneday.keybase.pub>
# this is version 0.1.0, last edited on 4 February 2019
# hey look it's skyworld!
# implemented:
# - going places
# - exiting
# - parsing info and directory lines in gophermaps
# - parsing HTML and plaintext lines in gophermaps
# - parsing TXT and MD files
# - displaying the current URL
# - quickly getting back to the root of a website
# - 404 errors when a document is not found
# - quick browsing for directories in Gophernicus
# to implement next:
# - quick browsing for files
# - formatting HTML files properly
# - nicer URLs
# - going back one URL in history
# - history, for that matter
import os
import time
url = ""
while True:
pygopherdException = False
if url is "":
url = input("yo where tf do you wanna go? ")
if url is "exit":
os.system("clear")
break
else:
addurl = input("yo where tf do you wanna go next? ")
if addurl == "exit" or addurl == "quit" or addurl == "leave":
os.system("clear")
break
elif addurl == "home":
wholeURL = url.split("/")
homeURL = wholeURL[0]
url = homeURL
elif addurl == "elsewhere":
url = ""
elif addurl.isdigit():
numerator = int(addurl) - 1
wholeURL = url.split("/")
homeURL = wholeURL[0]
url = homeURL
try:
url = url + "/1/" + directories[numerator] # this breaks with pygopherd
except: # catch pygopherd exception
pygopherdException = True
print("Error: Quick browsing isn't implemented with pygopherd yet.")
time.sleep(2)
directores = []
elif addurl is not "elsewhere":
url = url + addurl
content = os.popen("curl -s gopher://" + url).readlines()
if len(content) == 0 and url is not "":
print("404 not found")
elif url is not "":
os.system("clear")
if url[-2] == "m" or url[-2] == "x": # parsing HTML/Markdown/text files (hacky workaround; will almost always break)
print(" ")
for i in content:
newLineFix = i.rstrip()
print(newLineFix)
print(" ")
print("URL: gopher://" + str(url))
print(" ")
else:
acc = 0
directories = []
for i in content:
newLineFix = i.rstrip()
if newLineFix[0] == "i": # parsing info lines
if "null.host" in i: # for Gophernicus
info = newLineFix[1:].split("null.host")
print(info[0])
elif "(NULL)" in i: # for pygopherd
info = newLineFix[1:].split("(NULL)")
info2 = info[0]
print(info2[:-5])
elif newLineFix[0] == "1": # parsing directory lines
if newLineFix[-1] == "+": # for pygopherd
info = newLineFix[1:].split()
directory = info[-4]
directoryNameList = []
for i in range(len(info)):
directoryNameList.append(info[i])
for i in range(4):
del directoryNameList[-1]
directoryName = ""
for i in directoryNameList:
directoryName = directoryName + i + " "
acc = acc + 1
print("(" + str(acc) + ") (DIR) " + directoryName + ": /1" + directory)
else: # for Gophernicus (NEEDS FIXING)
info = newLineFix[1:].split()
directory = info[-3]
directoryNameList = []
for i in range(len(info)):
directoryNameList.append(info[i])
for i in range(2):
del directoryNameList[-1]
directoryName = ""
for i in directoryNameList:
if i[-1] == "/": # hack to get rid of trailing slash on tildeverse directory names
i = i[:-1]
directoryName = i[1:] + " "
acc = acc + 1
directories.append(directory)
print("(" + str(acc) + ") (DIR) " + directoryName + ": /1" + directory)
elif newLineFix[0] == "0" or newLineFix[0] == "h": # parsing links to text/HTML files
if newLineFix[-1] == "+": # for pygopherd
info = newLineFix[1:].split()
directory = info[-4]
directoryNameList = []
for i in range(len(info)):
directoryNameList.append(info[i])
for i in range(4):
del directoryNameList[-1]
directoryName = ""
for i in directoryNameList:
directoryName = directoryName + i + " "
print("(TEXT) " + directoryName + ": /1" + directory)
else: # for Gophernicus
info = newLineFix[1:].split()
directory = info[-3]
directoryNameList = []
for i in range(len(info)):
directoryNameList.append(info[i])
#for i in range(3):
# del directoryNameList[-1]
directoryName = ""
for i in directoryNameList:
if i[-1] == "/": # hack to get rid of trailing slash on tildeverse directory names
i = i[:-1]
directoryName = i[2:] + " "
print("(TEXT) /1" + directory) # this is broken as hell (no formatted file names) but I don't care right now
print(" ")
print(" ")
print("URL: gopher://" + str(url))
print(" ")