This commit is contained in:
BezierQuadratic 2022-04-02 00:25:53 +02:00
commit 86d289218d
9 changed files with 41 additions and 43 deletions

View file

@ -13,4 +13,6 @@
"networks_write":[],
"formats_read":[],
"formats_write":[],
"generic_name":["Social Media", "Photo Sharing", "Client"]}
"generic_name":["Instagram Client",
"Image Sharing",
"Social Network"]}

View file

@ -16,4 +16,4 @@
"ActivityPub"],
"formats_read":[],
"formats_write":[],
"generic_name":["Social Media", "Photo Sharing", "Fediverse"]}
"generic_name":["Social Network", "Image Sharing", "Messanger", "Fediverse"]}

View file

@ -9,34 +9,11 @@
from modules import search
import json
def isFree(licenses):
matches = 0
with open("licenses.json", "r") as data:
all_licenses = json.load(data)
for license in licenses:
for license2 in all_licenses["licenses"]:
if license2 == license:
matches = matches + 1
break
if matches == len(licenses):
return True
return False
def html(page, json):
# This function adds a rendering of the json into the page
# TODO: Add a more complex algorithm of checking if software is
# free or not. There are plenty of semi-free software like
# Unreal Engine. They have licenses but they do not give the users
# the four essential freedoms.
free = False
has_license = False
if "licenses" in json and json["licenses"]:
has_license = True
free = isFree(json["licenses"])
free = search.is_free(json)
page = page + "\n <h1>"
try:
page = page + '\n<img src="'+ json["links"]["icon"] + '" alt="Logo" style="width:50px;">'
@ -128,20 +105,22 @@ def suggestions(page, json):
# This function will render suggestions
page = page + "<br><br><h1>Free Competitors:</h1><br><br>"
page = page + "<h1>Free Competitors:</h1>"
found = search.suggest(json)
biggest = 0
for i in found:
if i[0] > biggest:
biggest = i[0]
for i in found:
free = False
if "licenses" in i[-1] and i[-1]["licenses"]:
has_license = True
free = isFree(i[-1]["licenses"])
free = search.is_free(i[-1])
if not i[0] or i[-1] == json or not free:
continue
page = page + "<br><br>"
page = page + "<hr><br>Features match: " + str(int(i[0]/biggest*100)) + "%"
page = html(page, i[-1])
return page
@ -163,7 +142,7 @@ def source_code_link(page):
# Adds a source code link
page = page + "<br><br><p>This website is under the GNU AGPL license.</p>"
page = page + "<br><br><hr><p>This website is under the GNU AGPL license.</p>"
page = page + """
<form action=https://notabug.org/jyamihud/FreeCompetitors>
<button type="submit">Source Code</button>

View file

@ -46,19 +46,22 @@ def search_app(name):
match = m
if closest:
return closest
return closest, match
match = 0
closest = {}
# Round 2. By Generic name
for i in all_apps:
for n in i.get("generic_name",[]):
m = similar(n.lower(), name.lower())
if m > match:
if m > match and is_free(i):
closest = i
match = m
if closest:
return closest
return closest, match
def suggest(json_data):
@ -97,3 +100,17 @@ def suggest(json_data):
fount = []
return found
def is_free(app):
if "licenses" in app and app["licenses"]:
matches = 0
with open("licenses.json", "r") as data:
all_licenses = json.load(data)
for license in app["licenses"]:
for license2 in all_licenses["licenses"]:
if license2 == license:
matches = matches + 1
break
if matches == len(app["licenses"]):
return True
return False

View file

@ -55,9 +55,9 @@ class handler(BaseHTTPRequestHandler):
# If the user is at the front page, let him get only the search bar
page = ""
page = "<center><br><br><br><h1>Free Competitors</h1>"
page = render.search_widget(page)
page = page + "<p>Please search for any software to which you would like to find a Free Software replacement.</p>"
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)
self.send(page)
@ -76,10 +76,10 @@ class handler(BaseHTTPRequestHandler):
software = self.path.replace("/", "").replace("+", " ")
software_data = search.search_app(software)
page = ""
page = render.search_widget(page)
software_data, match = search.search_app(software)
page = render.search_widget("")
page = page +"Search match: "+ str(int(match*100))+"%"
# Let's add the found software to the page
page = render.html(page, software_data)
page = render.suggestions(page, software_data)