Config file addition

This commit is contained in:
Matthew Evan 2022-04-03 12:27:21 -04:00
parent f4e8c83021
commit 7b2630a817
3 changed files with 24 additions and 8 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
port.json port.json
config.json
*.pyc *.pyc

View file

@ -145,16 +145,19 @@ def suggestions(page, json):
page = page + "</details>" page = page + "</details>"
return page return page
def search_widget(page): def search_widget(page, address):
# Adds a search bar to the page # Adds a search bar to the page
page = page + """ page = page + """
<form action="/search" method="GET"> <form action="""
page = page + address
page = page + """search method="GET">
<input type="text" name="item" class="search" placeholder="Name of Software"> <input type="text" name="item" class="search" placeholder="Name of Software">
<button type="submit">Search</button> <button type="submit">Search</button>
</form> </form>
""" """
#page = page.format(ADDRESS)
return page return page

View file

@ -18,11 +18,23 @@ from modules import render
CSS = "https://zortazert.codeberg.page/style/styles.css" CSS = "https://zortazert.codeberg.page/style/styles.css"
try: try:
with open("port.json","r") as f: if os.path.exists("config.json"):
json_stuff = json.load(f) with open("config.json","r") as f:
PORT = json_stuff["port"] srvConfig = json.load(f)
ADDRESS = srvConfig["address"]
PORT = srvConfig["port"]
CSS = srvConfig["css"]
except: except:
PORT = input("Port: ") newConfig = open("config.json", "w")
newConfig.write("""{
"INFO" : "You would be better off setting address to the full URL of the FreeCompetitors instance.",
"address" : "/",
"port" : "8080",
"css" : "https://zortazert.codeberg.page/style/styles.css"
}""")
newConfig.close
print("Please edit the configuration file \"config.json\".")
exit()
try: try:
PORT = int(PORT) PORT = int(PORT)
except: except:
@ -73,7 +85,7 @@ class handler(BaseHTTPRequestHandler):
# If the user is at the front page, let him get only the search bar # If the user is at the front page, let him get only the search bar
page = "<center><br><br><br><h1>Free Competitors</h1>" page = "<center><br><br><br><h1>Free Competitors</h1>"
page = render.search_widget(page) page = render.search_widget(page, ADDRESS)
page = page + "<p>Please search for any software to which you would like to find a Free Software replacement.</p></center>" page = page + "<p>Please search for any software to which you would like to find a Free Software replacement.</p></center>"
page = render.source_code_link(page) page = render.source_code_link(page)
self.send(page) self.send(page)
@ -95,7 +107,7 @@ class handler(BaseHTTPRequestHandler):
software_data, match = search.search_app(software) software_data, match = search.search_app(software)
page = render.search_widget("") page = render.search_widget("", ADDRESS)
page = page +"Search match: "+ str(int(match*100))+"%" page = page +"Search match: "+ str(int(match*100))+"%"
# Let's add the found software to the page # Let's add the found software to the page
page = render.html(page, software_data) page = render.html(page, software_data)