123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- # 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.
- from modules import search
- def html(page, json):
- # This function adds a rendering of the json into the page
- free = search.is_free(json)
- page = page + "\n <h1>"
- try:
- page = page + '\n<img src="'+ json["links"]["icon"] + '" alt="Logo" style="height:50px;">'
- except:
- pass
- name = json.get("names",["Unknown"])[0]
- page = page + "\n" + name
- page = page + "</h1>"
-
- # 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")
- os = comment[where:where+11]
- comment = comment.replace(os,
- "<a href=\"https://www.gnu.org/philosophy/open-source-misses-the-point.en.html\">"+os+"</a>")
- page = page + "<p>"+comment+"</p>"
- # I want to show nothing else from if it's proprietary
- if "issues" in json:
- l = json.get("issues", [])
- page = page +"<h2>Anti-Features / Problems:</h2>"
- for i in l:
- page = page + " "+i+"<br>"
-
- if not free:
- return page
-
- # Links
- # <table>
- # <tr>
- # <th>Company</th>
- # <th>Contact</th>
- # <th>Country</th>
- #</tr>
- page = page + """
- <style>
- table, th, td {
- border-right:none;
- border-left:none;
- border-bottom:none;
- border-top:none
- }</style>
- """
-
- page = page + "<table><tr>"
- links = json.get("links", {})
- for website in links:
- if website in ["icon"]:
- continue
- link = links[website]
- page = page + """
- <th><form action=\""""+link+"""\">
- <button title=\""""+link+"""\" type="submit">"""+website.upper()+"""</button>
- </form></th>
- """
- page = page + "</tr></table>"
- # 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
-
- page = page + "<details>"
- page = page +"<summary>"+categories[c]+":</summary>"
- for i in l:
- page = page + " "+i+"<br>"
- page = page + "</details>"
-
-
- return page
- def suggestions(page, json):
- # This function will render suggestions
- page = page + "<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] == json or not free:
- continue
- try:
- frac = int(i[0]/biggest*100)
- except:
- frac = 0
- if frac < 40 and not more: # Below 40% features match
- page = page + """<hr><details>
- <summary><h1 title="Click to show more / less.">Problematic Competitors:</h1></summary>"""
- more = True
-
- page = page + "<hr><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 + """
- <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>
- """
- #page = page.format(ADDRESS)
-
- return page
- def source_code_link(page):
- # Adds a source code link
- 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>
- </form><br><br>
- """
-
-
- return page
|