From 2cdaad98888818614176923e4c7e844e97be19bf Mon Sep 17 00:00:00 2001 From: jyamihud Date: Fri, 1 Apr 2022 22:59:32 +0300 Subject: [PATCH] UI tweaks / Match Percentages --- modules/__pycache__/render.cpython-38.pyc | Bin 2709 -> 2807 bytes modules/__pycache__/search.cpython-38.pyc | Bin 1820 -> 1998 bytes modules/render.py | 24 ++++++++++------------ modules/search.py | 17 ++++++++++++++- server.py | 6 +++--- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/modules/__pycache__/render.cpython-38.pyc b/modules/__pycache__/render.cpython-38.pyc index db8cf71bd5e007167e2c72e3e6a73d8b63aa7a87..ccb331d1b17c5214e6e62a371a000cc68c4475f3 100644 GIT binary patch delta 1106 zcmYjP&rcIU6rP#=HC@_Lfzn@~C={qfFM4Q@aFHk{E~uyxD|D82Q)ttfZA@@CJ>VZe zv(Xa=dNlFIAK*WrR}VdV!2?$lFZyP>pwsNk>wDk#y*Ka8hxD&>@@XPrBUq)a$GhK? zz2v*@F-FKkr`X4R91tHdoIwFPoC1qvkdK*`Lrl-13}S|iY@ucxBl&xQn&dekP6;!a zRl|M4XbuG$Fk`^fBpPfxI!B}$VB;*&2W6I2{w@)pm3y>?`XtbSkWvAC4Q;0a1O8tF zqDtNV=%Y<3ITlHdt5b?Y=+%rx7aM3JF$b9AA=OH0$UdC+fmW_F&68`xP2G+ z#i+P>kdOJc>fD0z$tz8&D=k6{uEa{2JR}2R9f-FjXehFYN=qAO%j6lx`dLqVg6#p_ zcdJfQI3oP1uVWhCGqy){PGFV;%N3P9?l@u3xP!Iui!p}_;SXbtdUDjJt%di^c6S== zs>EL|6Abx1gioBn1~sVR|9cLMz&Ht%orTHhjO1Xf4V~wQcA&NMD*8ImfkVIxj|HBQ zF^u!_(BtC<5f93~Ay~T%N%RczH1A5V0559-9pNKL&P>?^55_*E9ub&IIb5=4yBr=W zI{yRfFuPLct1G*F^^vpVb+{vD4tBh1eR<}b0p>R@mdvO#qEo9m!sDahA823u>kjc58JUnL}d&W+jhhK>aNgN&qLPdc>L;+Di0!5&h01{CIo{M88*z%rD5bViC zBnqma6CFafM1w?^2Js&#X)MvhFQ9~(vjq}+y4ksz{l5L?W`3pLrbq83lODr$xPIfw zr?EGqFFWr!W57cJLi0UKIu&1 zdC2PG0iNhGaKWqco`8`&3k^gj5NXh9^pnGVl-TfWXADw3fpp_>LIhvp@I;mML?{t3 z8OP-++e(Edeor9~rG%{cL9-2_Ob;nD@lK>xjnJ015VaiI+J-Ea_M_R?mPYZRgQy(x zUb)HrfNcRo8zA!xf9mqU0|RGf z8BA=MK{KK!lIOS-IW9y> zs5uthbqmog=j&zS_{ayh{KuCJ{Ku-YyM0iDs^5A=jB>zetA*n`Zkk_-5%U=QUrQ=z zv{l95t~9{k-mlg7B7$23ICmUXjJjU>8r6tu&@7NClKH11_TtiJP|l( L62jSW(oXUZ(*ey8 diff --git a/modules/__pycache__/search.cpython-38.pyc b/modules/__pycache__/search.cpython-38.pyc index 26c3beb88ec805f3486fc71976512f63f0336e46..6be2baabf5d80b44479e5812e437f39e7d55ce5b 100644 GIT binary patch delta 396 zcmXYtJxc>I7{~ME(p;|I)lv~!T12Q6ic)criVpP!-4wAR6ve*eY7dLhT*o^c>Ibl9 z5=0bNH$Q}%ICpXFN9gEt)xiIki#0ieivxDZ6Jxt`FGF&b@mWnuN3zsU833Sq;Cgo0BRC2?6X4J zoAky3+=D9Xb9w}hey3GyWP1K(TezZpz?gs}q%aHw<)HE(&jzDV*Ke^$ zz0K#STGYpU4R-W^Z{C*By9JT`|DZTW*~R!d1p0!c0lDTX9S}(~M5U#HUeUYQ;eJhY zy_S39yM9&0u)j!0Og8$B5sTcWr9W^yR2f7E;|l~a*V$BbS}qEez?w=S@Y}q0yX!So c" @@ -117,16 +111,20 @@ def suggestions(page, json): page = page + "

Free Competitors:

" 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"]: - free = True + + free = search.is_free(i[-1]) if not i[0] or i[-1] == json or not free: continue - #page = page + "

" + + page = page + "

Features match: " + str(int(i[0]/biggest*100)) + "%" page = html(page, i[-1]) return page diff --git a/modules/search.py b/modules/search.py index 1fb1478..eebf869 100644 --- a/modules/search.py +++ b/modules/search.py @@ -48,12 +48,15 @@ def search_app(name): if 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 @@ -97,3 +100,15 @@ def suggest(json_data): fount = [] return found + +def is_free(data): + + # 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 + if "licenses" in data and data["licenses"]: + free = True + return free diff --git a/server.py b/server.py index 89939b4..fddccf9 100644 --- a/server.py +++ b/server.py @@ -55,9 +55,9 @@ class handler(BaseHTTPRequestHandler): # If the user is at the front page, let him get only the search bar - page = "" + page = "



Free Competitors

" page = render.search_widget(page) - page = page + "

Please search for any software to which you would like to find a Free Software replacement.

" + page = page + "

Please search for any software to which you would like to find a Free Software replacement.

" page = render.source_code_link(page) self.send(page) @@ -79,7 +79,7 @@ class handler(BaseHTTPRequestHandler): software_data, match = search.search_app(software) page = render.search_widget("") - page = page +"Match: "+ str(match*100)+"%" + 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)