Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

__pycache__/ReaperEngine.cpython-310.pyc
internet.json
curpage.html
28 changes: 19 additions & 9 deletions ReaperEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ def __init__(self):
self.max_tokens = 4096
self.system_prompt = "You are an expert in creating realistic webpages. You do not create sample pages, instead you create webpages that are completely realistic and look as if they really existed on the web. You do not respond with anything but HTML, starting your messages with <!DOCTYPE html> and ending them with </html>. If a requested page is not a HTML document, for example a CSS or Javascript file, write that language instead of writing any HTML. If the requested page is instead an image file or other non-text resource, attempt to generate an appropriate resource for it instead of writing any HTML. You use very little to no images at all in your HTML, CSS or JS."

def _sanitize_links(self, dirty_html):
# Teensy function to replace all links on the page so they link to the root of the server
def _format_page(self, dirty_html):
# Teensy function to sanitize links on the page so they link to the root of the server
# Also to get rid of any http(s), this'll help make the link database more consistent

soup = BeautifulSoup(dirty_html, "html.parser")
for a in soup.find_all("a"):
print(a["href"])
Expand All @@ -28,12 +27,23 @@ def _sanitize_links(self, dirty_html):
a["href"] = a["href"].replace("http://", "")
a["href"] = a["href"].replace("https://", "")
a["href"] = "/" + a["href"]

# Create a new 'a' tag for the Home button
home_button = soup.new_tag("a", href="/")
home_button.string = "Home"

# Insert the Home button at the start of the body element
body = soup.body
if body:
body.insert(0, home_button)

return str(soup)

def get_index(self):
# Super basic start page, just to get everything going
return "<!DOCTYPE html><html><body><h3>Enter the Dead Internet</h3><form action='/' ><input name='query'> <input type='submit' value='Search'></form></body></html>"

# Load the HTML content from index.html
with open("index.html", "r") as file:
return file.read()

def get_page(self, url, path, query=None):
# Return already generated page if already generated page
try: return self.internet_db[url][path]
Expand Down Expand Up @@ -66,10 +76,10 @@ def get_page(self, url, path, query=None):
generated_page = generated_page_completion.choices[0].message.content
if not url in self.internet_db:
self.internet_db[url] = dict()
self.internet_db[url][path] = self._sanitize_links(generated_page)
self.internet_db[url][path] = self._format_page(generated_page)

open("curpage.html", "w+").write(generated_page)
return self._sanitize_links(generated_page)
return self._format_page(generated_page)

def get_search(self, query):
# Generates a cool little search page, this differs in literally every search and is not cached so be weary of losing links
Expand All @@ -87,7 +97,7 @@ def get_search(self, query):
max_tokens=self.max_tokens
)

return self._sanitize_links(search_page_completion.choices[0].message.content)
return self._format_page(search_page_completion.choices[0].message.content)

def export_internet(self, filename="internet.json"):
json.dump(self.internet_db, open(filename, "w+"))
Expand Down
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/styles.css">
</head>
<body>
<form action='/'>
<h3>Enter the Dead Internet</h3>
<input type='text' name='query' placeholder='Search'>
<input type='submit' value='Search'>
</form>
</body>
</html>
9 changes: 8 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import flask
import webbrowser
from urllib.parse import urlparse

from ReaperEngine import *
Expand All @@ -24,5 +25,11 @@ def index(path):
return generated_page

if __name__ == "__main__":
app.run()
# Use threading to open the browser a bit after the server starts
from threading import Timer
def open_browser():
webbrowser.open("http://127.0.0.1:5000")
Timer(1, open_browser).start() # Wait 1 second for the server to start

app.run(use_reloader=False) # Disable the reloader if it interferes with opening the browser
print(engine.export_internet())
73 changes: 73 additions & 0 deletions static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* Body and overall layout styles */
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

/* Form styling */
form {
display: flex;
flex-direction: column;
align-items: center;
}

/* Heading styles */
h3 {
font-size: 48px;
margin-bottom: 20px;
}

/* Text input styles */
input[type='text'] {
width: 400px;
height: 40px;
padding: 10px;
margin-bottom: 20px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 20px;
}

/* Submit button styles */
input[type='submit'] {
width: 100px;
height: 40px;
background-color: #e0e0e0;
border: 1px solid #f8f9fa;
color: black;
border-radius: 20px;
cursor: pointer;
font-size: 16px;
}

input[type='submit']:hover {
background-color: #c0c0c0;
}

/* Home button styles */
.home-button {
position: fixed;
top: 10px;
right: 10px;
padding: 10px 20px;
background-color: #007BFF;
color: white;
text-decoration: none;
border: none;
border-radius: 5px;
font-family: Arial, sans-serif;
font-size: 16px;
cursor: pointer;
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
transition: background-color 0.3s, box-shadow 0.3s;
}

.home-button:hover, .home-button:focus {
background-color: #0056b3;
box-shadow: 2px 2px 12px rgba(0,0,0,0.2);
outline: none;
}