From 2cd1122eb5c0b381530e9e3873cba175fa199c6d Mon Sep 17 00:00:00 2001 From: jyamihud Date: Mon, 11 Apr 2022 22:18:21 +0300 Subject: [PATCH] Added a checking algorithm V0.000000001 needs still work. --- apps/brave.json | 4 +- check.py | 108 ++++++++++++++++++++++++++++++++++++++++++++++ modules/render.py | 1 + modules/search.py | 40 ++++++++++++++++- 4 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 check.py diff --git a/apps/brave.json b/apps/brave.json index c5730f8..a2dc22c 100644 --- a/apps/brave.json +++ b/apps/brave.json @@ -2,9 +2,9 @@ "comment":"Browser which markets itself over good privacy and addblocker by default.", "links":{"website":"https://brave.com/", "wikipedia":"https://en.wikipedia.org/wiki/Brave_(web_browser)", - "git":"https://github.com/brave/brave-browser", + "git":"https://github.om/brave/brave-browser", "icon":"https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fcryptoradar.org%2Fwp-content%2Fuploads%2F2019%2F08%2FBrave-logo.png&f=1&nofb=1"}, - "licenses":["MPL-2.0"], + "licenses":["MPL-20"], "platforms":["Android", "Windows", "MacOS", diff --git a/check.py b/check.py new file mode 100644 index 0000000..4a6f7d4 --- /dev/null +++ b/check.py @@ -0,0 +1,108 @@ +# 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 +import json + +# TODO: Make a pull-request before starting + +print("* Checking...") + +# Check number one, list all missing software + +try: + with open("data/missing.json") as json_file: + missing = json.load(json_file) +except: + missing = {} + +if missing: + print() + print("* Missing Software found! Please copy-paste the next") + print(" section into our Missing Software Mega-Thread at: ") + print(" https://notabug.org/jyamihud/FreeCompetitors/issues/25") + print("===========================================================") + print() + +# TODO: Make it check if the items in the missing.json already added +# in the last pull-request, or manually by the operator. If they +# are found. Remove them from the file. And from the list. + +for i in missing: + name = i[0].upper()+i[1:].lower() + print(' - [ ] '+name+' *Searched at least '+str(missing[i]) +" times.*") + +if missing: + print() + print("===========================================================") + print() + +# Part two. Checking for healthy links + +import urllib.request +import urllib.error + +error = False +def iferror(): + if not error: + print() + print(" * Some files in 'apps' folder have problems! Please") + print(" copy-paste the next section into our Problems with") + print(" Software Mega-Thread at: ") + print(" https://notabug.org/jyamihud/FreeCompetitors/issues/24") + print("===========================================================") + print() + return True + +for f in os.listdir("apps"): + if f.endswith(".json"): + # Trying to read the file + try: + with open("apps/"+f) as json_file: + app = json.load(json_file) + except Exception as e: + error = iferror() + print(" - [ ] `apps/"+f+"` fails to load. Says: `"+str(e)+"`") + continue + + # Links + for link in app.get("links",[]): + + # TODO: Make the tester of the links closer to the kind + # of response that you will get in the web-browser. + + try: + urllib.request.urlopen(app.get("links",[])[link]) + except Exception as e: + if "403" not in str(e): + error = iferror() + print(" - [ ] `apps/"+f+"` "+link+" link doesn't seem to work.") + + # Licenses + lices = app.get("licenses", []) + try: + with open("data/licenses.json") as json_file: + ll = json.load(json_file)["licenses"] + except: + ll = {} + + for lic in lices: + + found = False + for l in ll: + if lic in [l.get("licenseId",""),l.get("name","")]: + found = True + if not found: + error = iferror() + print(" - [ ] `apps/"+f+"` License '"+lic+"' is unknown.") + + +print("===========================================================") +print() +print("* Check is finished!") +print() diff --git a/modules/render.py b/modules/render.py index 606a847..b446e6f 100644 --- a/modules/render.py +++ b/modules/render.py @@ -9,6 +9,7 @@ import os from modules import search + def html(page, json): # This function adds a rendering of the json into the page diff --git a/modules/search.py b/modules/search.py index 3beec51..f3ae8e9 100644 --- a/modules/search.py +++ b/modules/search.py @@ -48,6 +48,44 @@ def search_app(name): if closest: return closest, match + # If there was no match for the program by name + # we are saving the name into a special file so + # the operator of the website could see that there + # was a name that didn't have a file for it. + + # We open the 'missing.json' file + try: + with open("data/missing.json") as json_file: + missing = json.load(json_file) + except: + missing = {} + + # There could be a problem with writing so we look into it + # for a very close match. Up to about 60%. No more. + + match_missing = 0 + closest_missing = "" + for i in missing: + m = similar(i.lower(), name.lower()) + if m > match_missing and m > 0.6: + closest_missing = i + match_missing = 0 + write_to = closest_missing + if not write_to: + write_to = name + + # Now we add one number to it's mention + if write_to not in missing: + missing[write_to] = 1 + else: + missing[write_to] += 1 + + # Now we save the file + with open("data/missing.json", 'w') as f: + json.dump(missing, f, indent=4, sort_keys=True) + + + match = 0 closest = {} @@ -119,5 +157,5 @@ def is_free(app): if l in [al.get("licenseId",""),al.get("name","")]\ and al.get("isFsfLibre", False): return True - print("License Error! "+app.get("names",[])[0], "Check with data/licenses.json 'licenseId'") + #print("License Error! "+app.get("names",[])[0], "Check with data/licenses.json 'licenseId'") return False