check.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. import os
  8. import sys
  9. import json
  10. from modules import missing
  11. args = sys.argv
  12. if "--help" in args or "-h" in args:
  13. print("""You can use the next commands after check.py
  14. -links | Will skip checking the links
  15. --help | Displays this help menu""")
  16. exit()
  17. # TODO: Make a pull-request before starting
  18. print("* Checking...")
  19. # Check number one, list all missing software
  20. try:
  21. with open("data/missing.json") as json_file:
  22. miss = json.load(json_file)
  23. except:
  24. miss = {}
  25. if miss:
  26. print()
  27. print("* Missing Software found! Please copy-paste the next")
  28. print(" section into our Missing Software Mega-Thread at: ")
  29. print(" https://notabug.org/jyamihud/FreeCompetitors/issues/25")
  30. print("===========================================================")
  31. print()
  32. missing.List()
  33. if miss:
  34. print()
  35. print("===========================================================")
  36. print()
  37. # Part two. Checking for healthy links
  38. import urllib.request
  39. import urllib.error
  40. error = False
  41. def iferror():
  42. if not error:
  43. print()
  44. print(" * Some files in 'apps' folder have problems! Please")
  45. print(" copy-paste the next section into our Problems with")
  46. print(" Software Mega-Thread at: ")
  47. print(" https://notabug.org/jyamihud/FreeCompetitors/issues/24")
  48. print("===========================================================")
  49. print()
  50. return True
  51. for f in os.listdir("apps"):
  52. if f.endswith(".json"):
  53. # Trying to read the file
  54. try:
  55. with open("apps/"+f) as json_file:
  56. app = json.load(json_file)
  57. except Exception as e:
  58. error = iferror()
  59. print(" - [ ] `apps/"+f+"` fails to load. Says: `"+str(e)+"`")
  60. continue
  61. # Links
  62. if not "-links" in args:
  63. for link in app.get("links",[]):
  64. # TODO: Make the tester of the links closer to the kind
  65. # of response that you will get in the web-browser.
  66. try:
  67. urllib.request.urlopen(app.get("links",[])[link])
  68. except Exception as e:
  69. if "403" not in str(e):
  70. error = iferror()
  71. print(" - [ ] `apps/"+f+"` "+link+" link doesn't seem to work.")
  72. # Licenses
  73. lices = app.get("licenses", [])
  74. try:
  75. with open("data/licenses.json") as json_file:
  76. ll = json.load(json_file)["licenses"]
  77. except:
  78. ll = {}
  79. for lic in lices:
  80. found = False
  81. for l in ll:
  82. if lic in [l.get("licenseId",""),l.get("name","")]:
  83. found = True
  84. if not found:
  85. error = iferror()
  86. print(" - [ ] `apps/"+f+"` License '"+lic+"' is unknown.")
  87. print()
  88. print("===========================================================")
  89. print()
  90. print("* Check is finished!")
  91. print()