render.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # THIS SOFTWARE IS A PART OF FREE COMPETITOR PROJECT
  2. # THE FOLLOWING SOURCE CODE I UNDER THE GNU
  3. # AGPL LICENSE V3 OR ANY LATER VERSION.
  4. # This project is not for simple users, but for
  5. # web-masters and a like, so we are counting on
  6. # your ability to set it up and running.
  7. from modules import search
  8. def html(page, json):
  9. # This function adds a rendering of the json into the page
  10. free = search.is_free(json)
  11. page = page + "\n <h1>"
  12. try:
  13. page = page + '\n<img src="'+ json["links"]["icon"] + '" alt="Logo" style="width:50px;">'
  14. except:
  15. pass
  16. name = json.get("names",["Unknown"])[0]
  17. page = page + "\n" + name
  18. page = page + "</h1>"
  19. # Few words about it
  20. page = page + "<p>"+json.get("comment","")+"</p>"
  21. # I want to show nothing else from if it's proprietary
  22. if not free:
  23. l = json.get("issues", [])
  24. page = page +"<h2>Anti-Features / Problems:</h2>"
  25. for i in l:
  26. page = page + "<br>&nbsp;&nbsp;"+i
  27. return page
  28. # Links
  29. # <table>
  30. # <tr>
  31. # <th>Company</th>
  32. # <th>Contact</th>
  33. # <th>Country</th>
  34. #</tr>
  35. page = page + """
  36. <style>
  37. table, th, td {
  38. border-right:none;
  39. border-left:none;
  40. border-bottom:none;
  41. border-top:none
  42. }</style>
  43. """
  44. page = page + "<table><tr>"
  45. links = json.get("links", {})
  46. for website in links:
  47. if website in ["icon"]:
  48. continue
  49. link = links[website]
  50. page = page + """
  51. <th><form action=\""""+link+"""\">
  52. <button title=\""""+link+"""\" type="submit">"""+website.upper()+"""</button>
  53. </form></th>
  54. """
  55. page = page + "</tr></table>"
  56. # Details
  57. categories = {"generic_name":"Features",
  58. "licenses":"License(s)",
  59. "platforms":"Platforms",
  60. "networks_read":"Accesses Data from",
  61. "networks_write":"Interacts / Publishes to",
  62. "formats_read":"Opens from File-Formats",
  63. "formats_write":"Saves to File-Formats",
  64. "issues":"Anti-Features / Problems",
  65. "interface":"Interface",
  66. "languages":"Programming Languages"}
  67. for c in categories:
  68. l = json.get(c, [])
  69. if not l:
  70. continue
  71. page = page + "<details>"
  72. page = page +"<summary>"+categories[c]+":</summary>"
  73. for i in l:
  74. page = page + "&nbsp;&nbsp;"+i+"<br>"
  75. page = page + "</details>"
  76. return page
  77. def suggestions(page, json):
  78. # This function will render suggestions
  79. page = page + "<h1>Free Competitors:</h1>"
  80. found = search.suggest(json)
  81. biggest = 0
  82. for i in found:
  83. if i[0] > biggest:
  84. biggest = i[0]
  85. for i in found:
  86. free = search.is_free(i[-1])
  87. if not i[0] or i[-1] == json or not free:
  88. continue
  89. page = page + "<hr><br>Features match: " + str(int(i[0]/biggest*100)) + "%"
  90. page = html(page, i[-1])
  91. return page
  92. def search_widget(page):
  93. # Adds a search bar to the page
  94. page = page + """
  95. <form action="/search" method="GET">
  96. <input type="text" name="item" class="search" placeholder="Name of Software">
  97. <button type="submit">Search</button>
  98. </form>
  99. """
  100. return page
  101. def source_code_link(page):
  102. # Adds a source code link
  103. page = page + "<br><br><hr><p>This website is under the GNU AGPL license.</p>"
  104. page = page + """
  105. <form action=https://notabug.org/jyamihud/FreeCompetitors>
  106. <button type="submit">Source Code</button>
  107. </form><br><br>
  108. """
  109. return page