Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fresh top500 list from moz.com #10

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import sys

import sites
from sites import Sites

from multiprocessing import Pool

Expand All @@ -24,7 +24,7 @@ def setupDist():
try:
shutil.rmtree(dist)
except Exception as e:
print(e)
log(target="ERROR", message=f"removing {dist} failed", error=e)

os.mkdir(dist)
os.mkdir(top_sites)
Expand Down Expand Up @@ -70,10 +70,12 @@ def genSecurityTxtForDomain(
details["target"]: {
"rank": details["rank"],
"has_contact": details["has_contact"],
"has_dns_contact": True
if "dnssecuritytxt" in details
and details["dnssecuritytxt"]["security_contact"] is not None
else False,
"has_dns_contact": (
True
if "dnssecuritytxt" in details
and details["dnssecuritytxt"]["security_contact"] is not None
else False
),
}
}
if "http_security_txt" in details and details["http_security_txt"] != {}:
Expand Down Expand Up @@ -171,19 +173,20 @@ def genStaticFiles(results: dict):
genSecurityTxtForDomain((0, domain), gen_sites)
else:
domains_dict = {}
results_list = []

if os.environ.get("GET_SEC_TXT", "false") == "true":
domains_dict = (
sites.top500
) # {nn: sites.top500[nn] for nn in list(sites.top500)[:10]}
sites = Sites()
domains_dict = sites.getTop500()

if len(domains_dict) > 0:
print("Got domain lists, counts:")
print("Total -", len(domains_dict))
log(
target="INFO",
message="Got domain lists; total count {len(domains_dict)}",
)
else:
raise Exception("No domains")

results_list = []
with Pool(int(os.environ.get("POOL_SIZE", os.cpu_count()))) as p:
results_list = p.map(genSecurityTxtForDomain, domains_dict.items())

Expand Down
6 changes: 5 additions & 1 deletion jinja_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import json
import subresource_integrity as integrity

from json_logger import log


def colourFromLetter(letter: str = "") -> str:
if not letter:
Expand Down Expand Up @@ -94,7 +96,9 @@ def renderTemplate(
params.update({"title": params["dest_domain"]})
else:
description = ""
print(f"Skipping canonical and description for: {filename}")
log(
target="INFO", message=f"Skipping canonical and description for: {filename}"
)

params.update({"description": description})
params.update({"canonical": canonical})
Expand Down
10 changes: 4 additions & 6 deletions json_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ def log(
):
obj.update({"time": time.time()})

if target is not None and message is not None:
obj.update({"target": target, "message": str(message)})
elif target is not None:
obj.update({"message": str(target)})
if target is not None:
obj.update({"target": str(target)})

if error is not None:
obj.update({"error": str(error)})
obj.update({"message": str(message)})
obj.update({"error": str(error)})

print(
json.dumps(obj, default=str), file=sys.stdout if error is None else sys.stderr
Expand Down
Loading