sitescore.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # This program is Free Software. You can use it under the terms of GNU GPL v3 or any later
  2. # version of this license.
  3. # This is a very basic program meant to be re-implemented and extented. It's based on
  4. # the following article: https://odysee.com/@blenderdumbass:f/Web-Site-Score-System:4
  5. # and gives the user an information about a requested site. And a Freedom score.
  6. # First let's import a few things
  7. import urllib3 # with this we will get a copy of the data from the internet
  8. import json # with this we will parse the data
  9. # Now let's get the data
  10. url = "https://notabug.org/jyamihud/FreeSoftwareActivism/raw/master/SiteScores/scores.json"
  11. data = {}
  12. try:
  13. # Trying to download the file and parsing it
  14. http = urllib3.PoolManager()
  15. resp = http.request('GET', url)
  16. data = json.loads(resp.data.decode("utf-8"))
  17. print("Data Loaded. Type site name to see info, or exit to exit.")
  18. except Exception as e:
  19. # If the data isn't loaded, write that there was an error
  20. print("Can't load the data:", e)
  21. exit()
  22. # A little compliter: Anything that comes into "commands" will
  23. # be tabbable.
  24. commands = list(data.keys())
  25. commands.append("exit")
  26. commands.append("list")
  27. def completer(text, state):
  28. options = [i for i in commands if i.startswith(text)]
  29. if state < len(options):
  30. return options[state]
  31. else:
  32. return None
  33. # Importing this readline doesn't work everywhere.
  34. # so no tabs for windows users, I guess.
  35. try:
  36. import readline
  37. readline.parse_and_bind("tab: complete")
  38. readline.set_completer(completer)
  39. except:
  40. print("NO TABS, SORRY!")
  41. # Now that we have the data let's make a simple while loop
  42. # and a person will type names of sistes to see them in data
  43. # when typing exit, he will exit the loop, and the software
  44. while True:
  45. c = input(": ")
  46. if c == "exit": # If typed exit
  47. exit()
  48. elif c in data.keys(): # If info about the site exists
  49. # just print a bunch of stuff about the site
  50. yn = {True:"YES", False:"NO "} # A little Trur to Yes, False to No translator
  51. print("------------------------------------------")
  52. print("| |")
  53. # making center even, I gonna add this "e" which stands for "extra" _
  54. e = " " # Here \
  55. if len(c) % 2 == 0: # basically odd or even ? #
  56. e = "" #
  57. print("|"+" "*int(20-len(c)/2)+c.upper()+" "*int(20-len(c)/2)+ e +"|")
  58. print("| |")
  59. print("------------------------------------------")
  60. print(" SCORE: "+str(data[c]["score"]), " ("+str(data[c]["score"]/8*100)+"%)")
  61. print("------------------------------------------")
  62. print("| WORKS WITH TOR | "+yn[data[c]["0"]]+" |")
  63. print("| READABLE SOURCES | "+yn[data[c]["1"]]+" |")
  64. print("| FREE SOFTWARE JS | "+yn[data[c]["2"]]+" |")
  65. print("| WORKS WITHOUT JS | "+yn[data[c]["3"]]+" |")
  66. print("| NO DATA MINING | "+yn[data[c]["4"]]+" |")
  67. print("| NO DATA KEEPING | "+yn[data[c]["5"]]+" |")
  68. print("| FREE SOFT.SERVER | "+yn[data[c]["6"]]+" |")
  69. print("| FREE API | "+yn[data[c]["7"]]+" |")
  70. print("------------------------------------------")
  71. print("| LAST CHECKED | "+str(data[c]["last_reviewed"])+" |" )
  72. print("| CHECKED BY: |")
  73. print(" --------------")
  74. for i in data[c]["reviewed_by"]:
  75. print(" - "+str(i))
  76. print("------------------------------------------")
  77. note = str(data[c]["notes"])
  78. while note:
  79. e = ""
  80. if len(note) < 38:
  81. e = " "*(38-len(note))
  82. print("| "+ note[:38]+e+" |")
  83. note = note[38:]
  84. print("------------------------------------------")
  85. # I want to add a way of viewing a high score thing.
  86. elif c == "list":
  87. # We gonna list by the order of scores. The highest should be near the
  88. # end, since they are ones we want to promote. And things like Google
  89. # with 1 score whould be printed immediatly. So the user will not get
  90. # to thise site.
  91. star = {False:" ", True:"#"}
  92. for s in range(-1, 8):
  93. s = s + 1
  94. for site in data:
  95. if data[site]["score"] == s:
  96. # Let's make the star pattern
  97. stars = ""
  98. for i in range(8):
  99. stars = stars + " | " + star[data[site][str(i)]]
  100. print(stars+" | "+str(data[site]["score"])+" | "+str(data[site]["score"]/8*100)+"% "+site)
  101. print(" |---|---|---|---|---|---|---|---|-------|")
  102. print(" 0 1 2 3 4 5 6 7 SCORE % WEBSITE")
  103. print()
  104. print(" 0: WORKS WITH TOR 4: NO DATA MINING")
  105. print(" 1: READABLE SOURCES 5: NO DATA KEEPING")
  106. print(" 2: FREE SOFTWARE JS 6: FREE SOFT.SERVER")
  107. print(" 3: WORKS WITHOUT JS 7: FREE API")
  108. # If not found any command let's search for what was imputed.
  109. elif c: # If something is in command.
  110. found = 0 # We are going to count ho many
  111. print("|-------------------------------------------|")
  112. for site in data:
  113. if c.lower() in site.lower() or c.lower() in data[site]["notes"].lower():
  114. found = found + 1
  115. # What part of the notes to cut out into the frame
  116. place = data[site]["notes"].lower().find(c.lower())
  117. # clearing it, to fit nicely.
  118. if c.lower() in site.lower() or place < 10:
  119. place = 10
  120. if len(data[site]["notes"]) - place < 10:
  121. place = place - 9
  122. # printing the site, notes peace, score in ####
  123. print ("| "+site[:15]+" "*max(0, 15-len(site)), " | ", data[site]["notes"][place-10:place+10]+" | "+"#"*data[site]["score"])
  124. print("|-------------------------------------------|")
  125. # General info of how many found.
  126. print(" FOUND: "+str(found)+" WEBSITES")