Manually merging MattMadness' PR

This commit is contained in:
jyamihud 2022-04-03 21:04:47 +03:00
parent 9c87b660b8
commit 20e43552a4

View file

@ -1,3 +1,5 @@
#!/usr/bin/python3
# THIS SOFTWARE IS A PART OF FREE COMPETITOR PROJECT # THIS SOFTWARE IS A PART OF FREE COMPETITOR PROJECT
# THE FOLLOWING SOURCE CODE I UNDER THE GNU # THE FOLLOWING SOURCE CODE I UNDER THE GNU
# AGPL LICENSE V3 OR ANY LATER VERSION. # AGPL LICENSE V3 OR ANY LATER VERSION.
@ -15,16 +17,50 @@ import os
from modules import search from modules import search
from modules import render from modules import render
CSS = "https://zortazert.codeberg.page/style/styles.css" # Author: https://www.delftstack.com/howto/python/python-print-colored-text/
class bcolors:
OK = '\033[92m' #GREEN
WARNING = '\033[93m' #YELLOW
FAIL = '\033[91m' #RED
RESET = '\033[0m' #RESET COLOR
try: print("""╔═╗┬─┐┌─┐┌─┐╔═╗┌─┐┌┬┐┌─┐┌─┐┌┬┐┬┌┬┐┌─┐┬─┐┌─┐
Copyright (C) 2022 Jeison Yehuda Amihud
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
""")
print("Loading config...")
if os.path.exists("config.json"):
with open("config.json","r") as f: with open("config.json","r") as f:
srvConfig = json.load(f) srvConfig = json.load(f)
ADDRESS = srvConfig["address"] ADDRESS = srvConfig["address"]
PORT = srvConfig["port"] PORT = srvConfig["port"]
CSS = srvConfig["css"] CSS = srvConfig["css"]
print(bcolors.OK + "Loaded Configuration: " + bcolors.RESET)
print("Address: "+ ADDRESS)
print("Port: "+ str(PORT)) # Do not think people are smart at syntax
print("CSS: "+ CSS)
try:
PORT = int(PORT)
except: except:
print(bcolors.FAIL + "ERR: Port should be a number" + bcolors.RESET)
exit()
else:
newConfig = open("config.json", "w") newConfig = open("config.json", "w")
newConfig.write("""{ newConfig.write("""{
"INFO" : "You would be better off setting address to the full URL of the FreeCompetitors instance.", "INFO" : "You would be better off setting address to the full URL of the FreeCompetitors instance.",
@ -33,10 +69,9 @@ except:
"css" : "https://zortazert.codeberg.page/style/styles.css" "css" : "https://zortazert.codeberg.page/style/styles.css"
}""") }""")
newConfig.close newConfig.close
print("Please edit the configuration file \"config.json\".") print(bcolors.WARNING + "Please edit the configuration file \"config.json\"." + bcolors.RESET)
exit() exit()
# Who fucking made this http.server so I need to use classes? # Who fucking made this http.server so I need to use classes?
# I fucking hate who ever thought that it was a good idea... # I fucking hate who ever thought that it was a good idea...
class handler(BaseHTTPRequestHandler): class handler(BaseHTTPRequestHandler):
@ -113,4 +148,5 @@ class handler(BaseHTTPRequestHandler):
self.send(page) self.send(page)
serve = HTTPServer(("", PORT), handler) serve = HTTPServer(("", PORT), handler)
print(bcolors.OK + "⚡Now serving on port "+ str(PORT) +" at "+ ADDRESS +"." + bcolors.RESET)
serve.serve_forever() serve.serve_forever()