-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstring_14.py
More file actions
42 lines (40 loc) · 2.52 KB
/
Copy pathstring_14.py
File metadata and controls
42 lines (40 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
import requests
import json
from collections import OrderedDict
from inline import itest
def __main__():
# Define templates
CS_BASE_URL = "https://cheatsheetseries.owasp.org/cheatsheets/%s.html"
# Grab the index MD source from the GitHub repository
response = requests.get(
"https://raw.githubusercontent.com/OWASP/CheatSheetSeries/master/Index.md"
)
if response.status_code != 200:
print("Cannot load the INDEX content: HTTP %s received!" % response.status_code)
sys.exit(1)
else:
data = OrderedDict({})
for line in response.text.split("\n"):
if "(assets/Index_" in line:
work = line.strip()
# Extract the name of the CS
cs_name = work[1 : work.index("]")]
itest().given(work, "[Cross Site Scripting Prevention Cheat Sheet](cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.md).     ",).check_eq(cs_name, "Cross Site Scripting Prevention Cheat Sheet")
# Extract technologies and map the CS to them
technologies = work.split("!")[1:]
itest().given(work, "[Cross Site Scripting Prevention Cheat Sheet](cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.md).     ",).check_eq(technologies, ["[Javascript](assets/Index_Javascript.png) ", "[Java](assets/Index_Java.png) ", "[Csharp](assets/Index_Csharp.png) ", "[Html](assets/Index_Html.png) ", "[Ruby](assets/Index_Ruby.png)",],)
for technology in technologies:
technology_name = technology[1 : technology.index("]")].upper()
itest().given(technology, "[Javascript](assets/Index_Javascript.png) ").check_eq(technology_name, "JAVASCRIPT")
if technology_name not in data:
data[technology_name] = []
data[technology_name].append(
{
"CS_NAME": cs_name,
"CS_URL": CS_BASE_URL % cs_name.replace(" ", "_"),
}
)
# Display the built structure and formatted JSON
print(json.dumps(data, sort_keys=True, indent=1))
sys.exit(0)