92 lines
2.6 KiB
Python
92 lines
2.6 KiB
Python
# THIS SOFTWARE IS A PART OF FREE COMPETITOR PROJECT
|
|
# THE FOLLOWING SOURCE CODE I UNDER THE GNU
|
|
# AGPL LICENSE V3 OR ANY LATER VERSION.
|
|
|
|
# This project is not for simple users, but for
|
|
# web-masters and a like, so we are counting on
|
|
# your ability to set it up and running.
|
|
|
|
CSS = "https://zortazert.codeberg.page/style/styles.css"
|
|
PORT = input("Port: ")
|
|
try:
|
|
PORT = int(PORT)
|
|
except:
|
|
print("Port should be a number")
|
|
exit()
|
|
|
|
# Server side
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
from subprocess import *
|
|
import json
|
|
import os
|
|
|
|
from modules import search
|
|
from modules import render
|
|
|
|
# Who fucking made this http.server so I need to use classes?
|
|
# I fucking hate who ever thought that it was a good idea...
|
|
|
|
class handler(BaseHTTPRequestHandler):
|
|
|
|
def start_page(self):
|
|
self.send_response(200)
|
|
self.send_header('Content-type', 'text/html')
|
|
self.end_headers()
|
|
|
|
def send(self, text):
|
|
text = str(text)
|
|
csstext = '<link media="all" href="'+CSS+'" type="text/css" rel="stylesheet" />'
|
|
text = '<head>'+csstext+'</head><body>'+text+'</body>'
|
|
|
|
|
|
|
|
self.start_page()
|
|
self.wfile.write(text.encode("utf-8"))
|
|
|
|
def do_GET(self):
|
|
print(self.path)
|
|
|
|
if self.path == "/":
|
|
|
|
# If the user is at the front page, let him get only the search bar
|
|
|
|
self.send("""
|
|
<form action="/search" method="GET">
|
|
<input type="text" name="item" class="search" placeholder="Name of Software">
|
|
<input type="submit" value="Search">
|
|
</form>
|
|
""")
|
|
|
|
elif "/search?item=" in self.path:
|
|
|
|
# Clearing the url
|
|
# instead of it being /search?item=softwarename
|
|
# it will be just /softwarename
|
|
|
|
item = self.path[self.path.find("item=")+5:].lower()
|
|
self.send('<meta http-equiv="Refresh" content="0; url=\'/'+item+'\'" />')
|
|
|
|
else:
|
|
|
|
# This is when the fun is
|
|
|
|
software = self.path.replace("/", "").replace("+", " ")
|
|
|
|
software_data = search.search_app(software)
|
|
page = """
|
|
<form action="/search" method="GET">
|
|
<input type="text" name="item" class="search" placeholder="Name of Software">
|
|
<input type="submit" value="Search">
|
|
</form>
|
|
"""
|
|
|
|
|
|
# Let's add the found software to the page
|
|
page = render.html(page, software_data)
|
|
page = render.suggestions(page, software_data)
|
|
|
|
|
|
self.send(page)
|
|
|
|
serve = HTTPServer(("", PORT), handler)
|
|
serve.serve_forever()
|