forked from dispe1/Hackerrank-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateReadme.py
More file actions
63 lines (56 loc) · 2.91 KB
/
generateReadme.py
File metadata and controls
63 lines (56 loc) · 2.91 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import functools
def getFoldersNames(path):
folders = []
for item in os.listdir(path):
if not os.path.isfile(item) and item not in ('.git', '.idea'):
folders.append(item)
return folders
def getFilesNames(path):
files = os.listdir(path)
return files
def getProblemURLandScore(path):
inFile = open(path, 'r')
url = inFile.readline().split()[-1]
difficulty = inFile.readline().split()[-1]
score = inFile.readline().split()[-1]
inFile.close()
return url, difficulty, score
def getTotalNumberOfProblems():
totalNumber = 0
folders = getFoldersNames(os.getcwd())
for folder in folders:
subfolders = getFoldersNames(os.path.join(os.getcwd(), folder))
for subfolder in subfolders:
totalNumber += len(getFilesNames(os.path.join(os.getcwd(), folder, subfolder)))
return totalNumber
readmeFile = open('README.md', 'w')
readmeFile.write('# Solutions to Hackerrank practice problems\n')
readmeFile.write('This repository contains ' + str(getTotalNumberOfProblems()) + ' solutions to Hackerrank practice problems with Python 3.\n')
readmeFile.write('\n')
readmeFile.write('If it was helpful please press a star.\n')
readmeFile.write('\n')
readmeFile.write('[](https://github.com/dispe1/Hackerrank-Solutions)\n')
readmeFile.write('[](https://github.com/dispe1/Hackerrank-Solutions)\n')
readmeFile.write('[](https://github.com/dispe1/Hackerrank-Solutions)\n')
readmeFile.write('[](https://github.com/dispe1/Hackerrank-Solutions)\n')
readmeFile.write('\n')
folders = getFoldersNames(os.getcwd())
for folder in folders:
readmeFile.write('- ' + folder + '\n')
subfolders = getFoldersNames(os.path.join(os.getcwd(), folder))
for subfolder in subfolders:
readmeFile.write(' ' + subfolder + '\n')
files = getFilesNames(os.path.join(os.getcwd(), folder, subfolder))
for file in files:
url, difficulty, score = getProblemURLandScore(os.path.join(os.getcwd(), folder, subfolder, file))
readmeFile.write(' - ' + "".join(file.split(".")[1:-1])[1:]
+ ' | [Problem](' + url
+ ')'
+ ' | [Solution]'
+ '(https://github.com/dispe1/Hackerrank-Solutions/blob/master/'
+ folder.replace(' ', '%20') + '/' + subfolder.replace(' ', '%20') + '/'
+ file.replace(' ', '%20') + ')'
+ ' | Difficulty: ' + difficulty
+ ' | Score: ' + str(score) + '\n')
readmeFile.close()