This repository has been archived by the owner on Jun 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
clean.py
94 lines (70 loc) · 2.63 KB
/
clean.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import json
H4TT_VERSION = "2.2"
jsons = []
output = "![sreencast](poster.PNG)\n\n# Hack All The Things Round " + H4TT_VERSION + "\n"
def CleanFolders():
filenames = os.listdir (".")
blacklistFolders = [
".git",
"[template]"
]
folders = []
for filename in filenames:
if os.path.isdir(os.path.join(os.path.abspath("."), filename)):
folders.append(filename)
for folder in folders:
if folder in blacklistFolders:
continue
subFilenames = os.listdir ("./" + folder)
subFolders = []
for filename in subFilenames:
if os.path.isdir(os.path.join(os.path.abspath("./" + folder), filename)):
subFolders.append(filename)
for subFolder in subFolders:
newName = subFolder
newName = newName.lower()
newName = newName.replace(" ", "_")
newName = newName.replace("-", "_")
print subFolder
print newName
os.rename("./" + folder + "/" + subFolder, "./" + folder + "/" + newName)
def ScrapeJSON(output):
for root, dirs, files in os.walk("./"):
for file in files:
if file.endswith(".json"):
jsons.append(root + "/" + file)
categories = {}
for file in jsons:
with open(file) as thisJsonFile:
data = json.load(thisJsonFile)
thisCat = data['category'].lower()
if thisCat not in categories:
categories[thisCat] = {}
data['INTERNAL_PATH'] = file
categories[thisCat][data['title']] = data
return categories
def BuildReadme(categories, output):
listCat = []
for item in categories:
listCat.append(item)
listCat.sort()
for thisCat in listCat:
output += "## " + thisCat + "\n"
listChallPoints = []
for item in categories[thisCat]:
thisChall = categories[thisCat][item]
listChallPoints.append([int(thisChall['points']), thisChall['title']])
listChallPoints.sort()
for challenge in listChallPoints:
thisChall = categories[thisCat][challenge[1]]
output += "[" + thisChall['title'] + " | " + thisChall['points']
output += "](https://github.com/h4tt/H4TT-" + H4TT_VERSION + "/tree/master/" + thisCat + "/" + thisChall['INTERNAL_PATH'].split("/")[2] + ")\n\n"
return output
if __name__ == "__main__":
CleanFolders()
categories = ScrapeJSON(output)
output = BuildReadme(categories, output)
text_file = open("README.md", "w")
text_file.write(output)
text_file.close()