# 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. # Server side from http.server import BaseHTTPRequestHandler, HTTPServer from subprocess import * import json import os from modules import search from modules import render CSS = "https://zortazert.codeberg.page/style/styles.css" try: with open("port.json","r") as f: json_stuff = json.load(f) PORT = json_stuff["port"] except: PORT = input("Port: ") try: PORT = int(PORT) except: print("Port should be a number") exit() # 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) if "/json/" not in self.path: self.send_header('Content-type', 'text/html') else: self.send_header('Content-type', 'application/json') self.end_headers() def send(self, text): text = str(text) csstext = '' text = '
'+csstext+''+text+'' self.start_page() self.wfile.write(text.encode("utf-8")) def do_GET(self): if self.path.startswith("/json/"): # API CALL term = self.path[6:] software_data, match = search.search_app(term) data = {"found":{"data":software_data,"match":match}} data["suggestions"] = search.suggest(software_data) text = json.dumps(data, indent = 2) self.start_page() self.wfile.write(text.encode("utf-8")) elif self.path == "/": # If the user is at the front page, let him get only the search bar page = "Please search for any software to which you would like to find a Free Software replacement.