From 5457581ff2479023eddc321b85d16a16bc280a47 Mon Sep 17 00:00:00 2001 From: Patrick Carney Date: Wed, 24 Apr 2024 15:40:18 -0400 Subject: [PATCH 1/2] Added index page --- .gitignore | 4 ++++ ReaperEngine.py | 6 ++++-- index.html | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1382ff5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +__pycache__/ReaperEngine.cpython-310.pyc +internet.json +curpage.html diff --git a/ReaperEngine.py b/ReaperEngine.py index f11abb8..e88af2d 100644 --- a/ReaperEngine.py +++ b/ReaperEngine.py @@ -31,8 +31,10 @@ def _sanitize_links(self, dirty_html): return str(soup) def get_index(self): - # Super basic start page, just to get everything going - return "

Enter the Dead Internet

" + # 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 diff --git a/index.html b/index.html new file mode 100644 index 0000000..1f66639 --- /dev/null +++ b/index.html @@ -0,0 +1,53 @@ + + + + + + +
+

Enter the Dead Internet

+ + +
+ + From 4c7bba4499a71e122ca648ba65eb4b39c4e1b024 Mon Sep 17 00:00:00 2001 From: Patrick Carney Date: Wed, 24 Apr 2024 16:08:27 -0400 Subject: [PATCH 2/2] Added home button and styling --- ReaperEngine.py | 22 +++++++++----- index.html | 42 +-------------------------- main.py | 9 +++++- static/styles.css | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 49 deletions(-) create mode 100644 static/styles.css diff --git a/ReaperEngine.py b/ReaperEngine.py index e88af2d..7e447d9 100644 --- a/ReaperEngine.py +++ b/ReaperEngine.py @@ -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 and ending them with . 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"]) @@ -28,6 +27,16 @@ 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): @@ -35,7 +44,6 @@ def get_index(self): 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] @@ -68,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 @@ -89,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+")) diff --git a/index.html b/index.html index 1f66639..a1557ec 100644 --- a/index.html +++ b/index.html @@ -1,47 +1,7 @@ - +
diff --git a/main.py b/main.py index 7ff43ca..d2c8e66 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import flask +import webbrowser from urllib.parse import urlparse from ReaperEngine import * @@ -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()) diff --git a/static/styles.css b/static/styles.css new file mode 100644 index 0000000..c5cad88 --- /dev/null +++ b/static/styles.css @@ -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; +}