2022-03-29 12:44:03 +00:00
# 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.
2022-04-04 19:54:11 +03:00
import os
2022-03-29 12:44:03 +00:00
from modules import search
2022-04-02 00:10:18 +02:00
2022-04-11 22:18:21 +03:00
2022-03-29 12:44:03 +00:00
def html ( page , json ) :
# This function adds a rendering of the json into the page
2022-04-01 22:59:32 +03:00
free = search . is_free ( json )
2022-04-14 22:30:22 +03:00
name = json . get ( " names " , [ " Unknown " ] ) [ 0 ]
page = page + """
< ! - - For each software in the list we do mostly the same things .
And here it is . First we show it ' s name as a link to be able
to search Free Competitors to what is found . - - >
"""
page = page + " \n <a href= \" / " + name . replace ( " " , " + " ) . lower ( ) + " \" > "
page = page + " \n <h1> "
2022-03-29 12:44:03 +00:00
try :
2022-04-14 22:30:22 +03:00
page = page + ' \n <img src= " ' + json [ " links " ] [ " icon " ] + ' " alt= " [LOGO] " style= " height:50px; " > <!-- The logo of the software in question.--> \n '
2022-03-29 12:44:03 +00:00
except :
pass
2022-04-14 22:30:22 +03:00
page = page + " " + name + " <!-- The title of the program --> \n "
page = page + " </h1> \n </a> \n \n "
page = page + """
< ! - - Next there is a short paragraph about the program .
( Often Copypasted from some official page about it ) .
Which means , it may contain the terrible words " Open Source "
that hide the fact that Free Software is about User Freedom
first of all . So we are trying to link to a special page on
GNU . ORG if such a thing is found - - >
"""
2022-03-29 12:44:03 +00:00
# Few words about it
2022-04-02 14:11:49 +03:00
comment = json . get ( " comment " , " " )
2022-04-02 19:41:46 -05:00
not_foss = [ ' open source ' , ' open-source ' ]
if " open source " or " open-source " in comment . lower ( ) :
2022-04-02 14:11:49 +03:00
# Well... Here is a thing. Free Software, not open source.
where = comment . lower ( ) . find ( " open source " )
2022-04-02 19:41:46 -05:00
# In case it has a slash in it.
if where == - 1 :
where = comment . lower ( ) . find ( " open-source " )
2022-04-04 19:54:11 +03:00
ops = comment [ where : where + 11 ]
2022-04-14 22:30:22 +03:00
if ops :
comment = comment . replace ( ops ,
" <a href= \" https://www.gnu.org/philosophy/open-source-misses-the-point.en.html \" > " + ops + " </a> " )
page = page + " \n <p> \n " + comment + " \n </p> \n \n "
2022-03-29 12:44:03 +00:00
2022-03-31 21:08:42 +03:00
# I want to show nothing else from if it's proprietary
2022-04-04 19:54:11 +03:00
issues_files = list ( os . listdir ( " data/issues " ) )
2022-04-02 18:28:29 +03:00
if " issues " in json :
2022-03-31 21:08:42 +03:00
l = json . get ( " issues " , [ ] )
page = page + " <h2>Anti-Features / Problems:</h2> "
for i in l :
2022-04-04 19:54:11 +03:00
if i + " .html " not in issues_files :
page = page + " " + i + " <br> "
else :
page = page + ' <details title= " Read about ' + i + ' " > '
page = page + " <summary>   " + i + " </summary> "
issuefile = open ( " data/issues/ " + i + " .html " )
page = page + " <span><p> " + issuefile . read ( ) + " </p></span> "
page = page + " </details> "
2022-04-02 18:28:29 +03:00
if not free :
2022-03-31 21:08:42 +03:00
return page
2022-03-29 12:44:03 +00:00
# Links
2022-03-30 16:12:06 +00:00
2022-04-14 22:30:22 +03:00
page = page + """
< ! - - To organize the buttons with the main links we are using
a table . But since I don ' t know what CSS file the maintainer
will choose . And I want the table to be invisible . I insert here
a bit of CSS code . - - >
"""
2022-03-30 16:12:06 +00:00
page = page + """
< style >
2022-04-14 22:30:22 +03:00
table , th , td {
border - right : none ;
border - left : none ;
border - bottom : none ;
border - top : none
}
< / style >
< ! - - And now the table itself . - - >
2022-03-30 16:12:06 +00:00
"""
page = page + " <table><tr> "
2022-04-05 21:21:04 +03:00
linksfilter = { " git " : " source " }
2022-03-31 21:08:42 +03:00
links = json . get ( " links " , { } )
for website in links :
if website in [ " icon " ] :
continue
link = links [ website ]
2022-03-31 12:16:16 -05:00
page = page + """
2022-04-14 22:30:22 +03:00
< ! - - Here ' s how to do a simple button -->
< th >
< form action = \""" " +link+ """ \" > <!-- You make a form with a link -->
< button title = \""" " +link+ """ \" type= " submit " > " " " + linksfilter . get ( website , website ) . upper ( ) + """ </button> <!-- And you activare that form with a button -->
< / form >
< / th >
2022-03-31 12:16:16 -05:00
"""
2022-03-30 16:12:06 +00:00
page = page + " </tr></table> "
2022-04-14 22:30:22 +03:00
page = page + """
< ! - - Details are those little collapsable things that I like to
use very much . It ' s very simple really. Just read the code
carefully and you will get it - - >
"""
2022-03-30 16:12:06 +00:00
# Details
categories = { " generic_name " : " Features " ,
" licenses " : " License(s) " ,
" platforms " : " Platforms " ,
" networks_read " : " Accesses Data from " ,
" networks_write " : " Interacts / Publishes to " ,
" formats_read " : " Opens from File-Formats " ,
" formats_write " : " Saves to File-Formats " ,
2022-03-31 21:23:41 +03:00
" interface " : " Interface " ,
" languages " : " Programming Languages " }
2022-03-30 16:12:06 +00:00
for c in categories :
l = json . get ( c , [ ] )
if not l :
continue
2022-04-07 20:22:31 +03:00
# I want to look whether this category has a list of files
alldata = list ( os . listdir ( " data " ) )
allfiles = [ ]
for folder in alldata :
if c . startswith ( folder ) :
try :
allfiles = list ( os . listdir ( " data/ " + folder ) )
break
except :
pass
# Count matches
matches = 0
for i in l :
if i . startswith ( " * " ) :
matches + = 1
if matches :
matchtext = " <i>( " + str ( matches ) + " )</i> "
else :
matchtext = " "
2022-04-14 22:30:22 +03:00
page = page + " \n \n <details> "
page = page + " \n <summary> " + categories [ c ] + " : " + matchtext + " </summary> "
2022-03-30 16:12:06 +00:00
for i in l :
2022-04-07 20:22:31 +03:00
matchtext = " "
if i . startswith ( " * " ) :
i = i [ 1 : ]
matchtext = " <i>( match )</i> "
if i + " .html " in allfiles :
datapage = open ( " data/ " + folder + " / " + i + " .html " )
2022-04-14 22:30:22 +03:00
page = page + """
< ! - - Just so happened that about \""" " +i+ """ \" we had a file
in data / """ +folder+ """ folder . So why not make a detail inside a detail ,
a detail - sception , so to speak . And add the text of explanation into it . - - >
"""
page = page + " <details> \n "
page = page + " <summary> " + matchtext + i + " </summary> \n "
page = page + " <span> \n <p> \n "
page = page + " " + datapage . read ( ) + " \n "
page = page + " </p> \n </span> \n </details> "
2022-04-07 20:22:31 +03:00
else :
2022-04-14 22:30:22 +03:00
page = page + " \n <span> " + matchtext + i + " </span> \n <br> \n "
page = page + """
< ! - - Just a tiny space after all the spans . So no to feel
too crowded , so to speak - - >
< span > < br > < / span >
< / details >
"""
2022-03-30 16:12:06 +00:00
2022-03-29 12:44:03 +00:00
return page
def suggestions ( page , json ) :
# This function will render suggestions
2022-04-14 22:30:22 +03:00
page = page + """
< ! - - == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
This is where ther actual competitors are starting to show ! ! !
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == - - >
< h1 > Free Competitors : < / h1 >
"""
2022-03-29 12:44:03 +00:00
found = search . suggest ( json )
2022-04-01 22:59:32 +03:00
biggest = 0
for i in found :
if i [ 0 ] > biggest :
biggest = i [ 0 ]
2022-04-02 18:28:29 +03:00
more = False
2022-03-29 12:44:03 +00:00
for i in found :
2022-04-01 22:59:32 +03:00
free = search . is_free ( i [ - 1 ] )
2022-03-30 17:52:36 +00:00
2022-04-08 19:11:38 +03:00
if not i [ 0 ] or i [ - 1 ] [ " names " ] == json [ " names " ] or not free :
2022-03-29 12:44:03 +00:00
continue
2022-04-02 18:28:29 +03:00
try :
frac = int ( i [ 0 ] / biggest * 100 )
except :
frac = 0
2022-04-07 20:22:31 +03:00
if frac < 20 and not more : # Below 40% features match
2022-04-14 22:30:22 +03:00
page = page + """
< ! - - Sometimes the suggestion is not very good . Below 40 %
of suggestion score . But it still kind of valid . So we
want to put it into the page . Only when the user clicks
something . Why not using the same old details ? - - >
< hr >
< details >
< summary > < h1 title = " Click to show more / less. " > Problematic Competitors : < / h1 > < / summary >
"""
2022-04-02 18:28:29 +03:00
more = True
2022-04-14 22:30:22 +03:00
page = page + """
2022-04-02 18:28:29 +03:00
2022-04-14 22:30:22 +03:00
< hr >
< ! - - == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == - - >
"""
page = page + " <br>Suggestion score: " + str ( frac ) + " % "
2022-03-29 12:44:03 +00:00
page = html ( page , i [ - 1 ] )
2022-04-02 18:28:29 +03:00
if more :
page = page + " </details> "
2022-03-30 16:12:06 +00:00
return page
2022-04-03 12:27:21 -04:00
def search_widget ( page , address ) :
2022-03-30 16:12:06 +00:00
# Adds a search bar to the page
page = page + """
2022-04-14 22:30:22 +03:00
< ! - - Search widget ! This widget makes it possible to implement
a search feature without using a single line of JavaScript code .
In HTML , there is an input field that we can use . If we pare it
with a button into a < form > , we can get a button that activates
the search . - - >
2022-04-03 12:27:21 -04:00
< form action = """
page = page + address
page = page + """ search method= " GET " >
2022-03-30 16:12:06 +00:00
< input type = " text " name = " item " class = " search " placeholder = " Name of Software " >
< button type = " submit " > Search < / button >
< / form >
2022-04-14 22:30:22 +03:00
< ! - - And that ' s it for the search widget -->
2022-03-30 16:12:06 +00:00
"""
2022-04-03 12:27:21 -04:00
#page = page.format(ADDRESS)
2022-03-30 16:12:06 +00:00
return page
def source_code_link ( page ) :
# Adds a source code link
page = page + """
2022-04-14 22:30:22 +03:00
< ! - - This the the footer of every page - - >
< br >
< br >
< hr >
< p > This website is under the GNU AGPL license . < / p >
< ! - - As always I want to add a bit of CSS to make tables
invisible - - >
2022-04-04 21:52:17 +03:00
< style >
2022-04-14 22:30:22 +03:00
table , th , td {
border - right : none ;
border - left : none ;
border - bottom : none ;
border - top : none
}
< / style >
< ! - - This is self explanatory ( if you read most of the page ) - - >
2022-04-04 21:52:17 +03:00
< table > < tr >
< th > < form action = https : / / notabug . org / jyamihud / FreeCompetitors >
2022-04-05 21:21:04 +03:00
< button title = " See the full source code of the software that powers this website. " type = " submit " > SOURCE < / button >
< / form > < / th >
2022-04-06 22:03:07 +03:00
< th > < form action = / faq >
< button title = " Frequently Asked Questions " type = " submit " > FAQ < / button >
< / form > < / th >
2022-04-05 21:21:04 +03:00
< th > < form action = https : / / notabug . org / jyamihud / FreeCompetitors / issues >
< button title = " Report a bug. " type = " submit " > BUG ? < / button >
2022-04-04 21:52:17 +03:00
< / form > < / th >
2022-04-05 21:21:04 +03:00
2022-04-04 21:52:17 +03:00
< th > < form action = https : / / notabug . org / jyamihud / FreeCompetitors / issues / 25 >
2022-04-05 21:21:04 +03:00
< button title = " Report a piece of software that ' s missing from the catalogue. " type = " submit " > MISSING ? < / button >
2022-04-04 21:52:17 +03:00
< / form > < / th >
< th > < form action = https : / / notabug . org / jyamihud / FreeCompetitors / issues / 24 >
2022-04-05 21:21:04 +03:00
< button title = " Report a mistake in data about software. " type = " submit " > MISTAKE ? < / button >
2022-04-14 22:30:22 +03:00
< / form > < / th > < / tr >
< / table >
< br >
< br >
< ! - - And this was the page of Free Competitors . No Javascript .
No crap . No trackers . No nothing . And still works . Take that
Google ! ! ! - - >
2022-04-04 21:52:17 +03:00
2022-03-30 16:12:06 +00:00
"""
2022-03-29 12:44:03 +00:00
return page