Added a favicon

This commit is contained in:
jyamihud 2022-04-15 20:40:53 +03:00
parent 1f3459e7f2
commit bfd9a843ef
5 changed files with 420 additions and 1 deletions

View file

@ -0,0 +1,20 @@
[
1650038528.6090891,
1650038640.6455874,
1650038641.8818197,
1650038643.079802,
1650038644.242559,
1650038645.3251307,
1650038646.4718275,
1650038647.479486,
1650038648.4314067,
1650038649.4624548,
1650038650.494474,
1650043243.9023528,
1650043460.1411445,
1650043460.315897,
1650043490.4135377,
1650043958.2914546,
1650043959.0416543,
1650044037.8992538
]

BIN
favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

360
modules/#render.py# Normal file
View file

@ -0,0 +1,360 @@
# 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.
import os
from modules import search
def html(page, json):
# This function adds a rendering of the json into the page
free = search.is_free(json)
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>"
try:
page = page + '\n <img src="'+ json["links"]["icon"] + '" alt="[LOGO]" style="height:50px;"> <!-- The logo of the software in question.-->\n'
except:
pass
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 -->
"""
# Few words about it
comment = json.get("comment","")
not_foss = ['open source', 'open-source']
if "open source" or "open-source" in comment.lower():
# Well... Here is a thing. Free Software, not open source.
where = comment.lower().find("open source")
# In case it has a slash in it.
if where == -1:
where = comment.lower().find("open-source")
ops = comment[where:where+11]
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"
# I want to show nothing else from if it's proprietary
issues_files = list(os.listdir("data/issues"))
if "issues" in json:
l = json.get("issues", [])
page = page +"<h2>Anti-Features / Problems:</h2>"
for i in l:
if i+".html" not in issues_files:
page = page + "&nbsp;&nbsp;"+i+"<br>"
else:
page = page + '<details title="Read about '+i+'">'
page = page + "<summary>&nbsp;&nbsp"+i+"</summary>"
issuefile = open("data/issues/"+i+".html")
page = page + "<span><p>"+issuefile.read()+"</p></span>"
page = page + "</details>"
if not free:
return page
# Links
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. -->
"""
page = page + """
<style>
table, th, td {
border-right:none;
border-left:none;
border-bottom:none;
border-top:none
}
</style>
<!-- And now the table itself. -->
"""
page = page + "<table><tr>"
linksfilter = {"git":"source"}
links = json.get("links", {})
for website in links:
if website in ["icon"]:
continue
link = links[website]
page = page + """
<!-- 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>
"""
page = page + "</tr></table>"
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 -->
"""
# 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",
"interface":"Interface",
"languages":"Programming Languages"}
for c in categories:
l = json.get(c, [])
if not l:
continue
# 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 = ""
page = page + "\n\n <details>"
page = page +"\n <summary>"+categories[c]+": "+matchtext+"</summary>"
for i in l:
matchtext = ""
if i.startswith("*"):
i = i[1:]
matchtext = "&nbsp;&nbsp;&nbsp;&nbsp;<i>( match )</i> "
if i+".html" in allfiles:
datapage = open("data/"+folder+"/"+i+".html")
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>&nbsp;&nbsp;&nbsp;&nbsp;"+matchtext+i+"</summary>\n"
page = page + " <span>\n <p>\n"
page = page + " " + datapage.read()+"\n"
page = page + " </p>\n </span>\n </details>"
else:
page = page + "\n <span>&nbsp;&nbsp;&nbsp;&nbsp;"+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>
"""
return page
def suggestions(page, json):
# This function will render suggestions
page = page + """
<!-- ===========================================================
This is where ther actual competitors are starting to show!!!
============================================================ -->
<h1>Free Competitors:</h1>
"""
found = search.suggest(json)
biggest = 0
for i in found:
if i[0] > biggest:
biggest = i[0]
more = False
for i in found:
free = search.is_free(i[-1])
if not i[0] or i[-1]["names"] == json["names"] or not free:
continue
try:
frac = int(i[0]/biggest*100)
except:
frac = 0
if frac < 20 and not more: # Below 40% features match
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>
"""
more = True
page = page +"""
<hr>
<!-- ================================================================== -->
"""
page = page + "<br>Suggestion score: " + str(frac) + "%"
page = html(page, i[-1])
if more:
page = page + "</details>"
return page
def search_widget(page, address):
# Adds a search bar to the page
page = page + """
<!-- 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. -->
<form action="""
page = page + address
page = page + """search method="GET">
<input type="text" name="item" class="search" placeholder="Name of Software">
<button type="submit">Search</button>
</form>
<!-- And that's it for the search widget -->
"""
#page = page.format(ADDRESS)
return page
def source_code_link(page):
# Adds a source code link
page = page + """
<!-- 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 -->
<style>
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 ) -->
<table><tr>
<th><form action=https://notabug.org/jyamihud/FreeCompetitors>
<button title="See the full source code of the software that powers this website." type="submit">SOURCE</button>
</form></th>
<th><form action=/faq>
<button title="Frequently Asked Questions" type="submit">FAQ</button>
</form></th>
<th><form action=https://notabug.org/jyamihud/FreeCompetitors/issues>
<button title="Report a bug." type="submit">BUG?</button>
</form></th>
<th><form action=https://notabug.org/jyamihud/FreeCompetitors/issues/25>
<button title="Report a piece of software that's missing from the catalogue." type="submit">MISSING?</button>
</form></th>
<th><form action=https://notabug.org/jyamihud/FreeCompetitors/issues/24>
<button title="Report a mistake in data about software." type="submit">MISTAKE?</button>
</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!!! -->
"""
return page

1
modules/.#render.py Symbolic link
View file

@ -0,0 +1 @@
vcs@vcs-Lenovo-IdeaPad-S145-15IWL.3286:1650042546

View file

@ -13,6 +13,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
from subprocess import * from subprocess import *
import json import json
import os import os
import time
from modules import search from modules import search
from modules import render from modules import render
@ -84,16 +85,21 @@ class handler(BaseHTTPRequestHandler):
self.send_header('Content-type', 'text/css') self.send_header('Content-type', 'text/css')
elif self.path == "/ttf": elif self.path == "/ttf":
self.send_header('Content-type', 'font/ttf') self.send_header('Content-type', 'font/ttf')
elif self.path in ["/favicon.png", "/logo"]:
self.send_header('Content-type', 'image/png')
else: else:
self.send_header('Content-type', 'text/html') self.send_header('Content-type', 'text/html')
self.end_headers() self.end_headers()
def send(self, textin): def send(self, textin):
textin = str(textin) textin = str(textin)
csstext = '<link media="all" href="'+CSS+'" type="text/css" rel="stylesheet" />' csstext = '<link media="all" href="'+CSS+'" type="text/css" rel="stylesheet" />'
text = "<!-- Welcome to Free Competitors Page Source!!!--> \n\n" text = "<!-- Welcome to Free Competitors Page Source!!!--> \n\n"
text = text + "<!-- Let's add some CSS, you can edit 'config.json' to change it. -->\n" text = text + "<!-- Let's add some CSS, you can edit 'config.json' to change it. -->\n"
text = text + '<head>'+csstext+'</head>\n\n' text = text + '<head>'+csstext+'</head>\n\n'
text = text + "<!-- Now we want the favicon to be PNG instead of ICO -->\n\n"
text = text + '<link rel="icon" href="favicon.png">'
text = text + "<!-- Now the body. The main part of the page, so to speak. -->\n" text = text + "<!-- Now the body. The main part of the page, so to speak. -->\n"
text = text + '<body>\n\n'+textin+'\n\n</body>' text = text + '<body>\n\n'+textin+'\n\n</body>'
@ -117,13 +123,19 @@ class handler(BaseHTTPRequestHandler):
self.start_page() self.start_page()
self.wfile.write(text.encode("utf-8")) self.wfile.write(text.encode("utf-8"))
elif self.path == "/": elif self.path == "/":
# 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>
<img src="/logo" alt="[LOGO]" style="height:150px;">
<h1>Free Competitors</h1>"""
page = render.search_widget(page, ADDRESS) 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)
@ -155,7 +167,33 @@ class handler(BaseHTTPRequestHandler):
faqfile = render.source_code_link(faqfile) faqfile = render.source_code_link(faqfile)
self.send(faqfile) self.send(faqfile)
elif "/favicon.png" == self.path:
# I'm recording all the favicons request times to get
# a rough estimate of how many people visit when.
# It seems like the browser is visiting the site for
# the first time ( at least in a given session ) it
# asks for a 'favicon.ico'. So I store each of those
# requests time. As a timestamp.
try:
with open("data/favicon_requests.json") as json_file:
favicons = json.load(json_file)
except:
favicons = []
favicons.append(time.time())
with open("data/favicon_requests.json", 'w') as f:
json.dump(favicons, f, indent=4, sort_keys=True)
icon = open("favicon.png", "rb")
icon = icon.read()
self.wfile.write(icon)
elif "/logo" == self.path:
icon = open("favicon.png", "rb")
icon = icon.read()
self.wfile.write(icon)
elif "/search?item=" in self.path: elif "/search?item=" in self.path: