update scripts
This commit is contained in:
@ -1,18 +1,10 @@
|
||||
import autopep8
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
print(sys.version)
|
||||
files = os.listdir('snippets')
|
||||
codeRe = "```\s*python([\s\S]*?)```"
|
||||
for file in files:
|
||||
someFile = open("snippets/" + file)
|
||||
fileData = someFile.read()
|
||||
someFile.close()
|
||||
originalCode = re.search(codeRe,fileData).group(0)
|
||||
#print(re.split(codeRe,fileData)[0])
|
||||
formatedCode = '\n'+autopep8.fix_code(re.split(codeRe,fileData)[1]).strip()+'\n'
|
||||
fileToSave = fileData.replace(originalCode,('```python'+formatedCode+'```'))
|
||||
someFile = open("snippets/"+file,'w')
|
||||
someFile.write(fileToSave)
|
||||
someFile.close()
|
||||
import util
|
||||
snippets = util.read_snippets()
|
||||
for snippet in snippets:
|
||||
formatedCode = autopep8.fix_code(snippet.read_code()).strip()
|
||||
fixedCode = snippet.content.replace(snippet.read_code(),formatedCode)
|
||||
snippetFile = open(f"snippets/{snippet.name}.md",'w')
|
||||
snippetFile.write(fixedCode)
|
||||
snippetFile.close()
|
||||
@ -27,6 +27,7 @@ start = util.read_readme_start()
|
||||
end = util.read_readme_end()
|
||||
toAppend = ''
|
||||
tag_dict = tagger()
|
||||
author_database = util.author_reader()
|
||||
for category in sorted(tag_dict):
|
||||
toAppend = toAppend + '### ' + EMOJIS[category] + ' ' + title_case(category) +'\n\n<details><summary>View contents</summary> <ul>'
|
||||
for snippet in sorted(tag_dict[category],key=lambda snippet : snippet.name):
|
||||
@ -34,8 +35,9 @@ for category in sorted(tag_dict):
|
||||
toAppend += '</ul></details>\n\n'
|
||||
toAppend += '<hr></hr> \n\n'
|
||||
for category in sorted(tag_dict):
|
||||
toAppend = toAppend + '## ' + EMOJIS[category] + ' ' + title_case(scategory) +'\n\n'
|
||||
toAppend = toAppend + '## ' + EMOJIS[category] + ' ' + title_case(category) +'\n\n'
|
||||
for snippet in sorted(tag_dict[category],key=lambda snippet : snippet.name):
|
||||
fileData = someFile.read()
|
||||
toAppend += f'###{snippet.title}\n\n```py{snippet.read_code()} \n ```'.format(codeParts= codeParts) +codeParts[2] + '<details><summary>View Examples</summary>\n\n```py\n{codeParts[3]}\n```\n</details>\n\n<br><a href = "#table-of-contents">:arrow_up: Back to top</a>\n '.format(codeParts=codeParts) + '\n'
|
||||
open("README.md",'w').write(start+toAppend+'\n'+end)'''
|
||||
author,contributors = author_database[snippet.name]
|
||||
contributors = ', '.join(contributors)
|
||||
toAppend += f'### {snippet.name} \n<span style="color:grey">Author:-</span> {author} \n <span style="color:grey">Contributors:-</span>{contributors}\n\n{snippet.read_description()}\n```py\n{snippet.read_code()}\n```\n<details><summary>View Examples</summary>\n\n```py\n{snippet.read_example()}\n```\n</details>\n\n<br><a href = "#table-of-contents">:arrow_up: Back to top</a>\n\n'
|
||||
open("README.md",'w').write(start+toAppend+'\n'+end)
|
||||
@ -1,6 +1,21 @@
|
||||
import os,re
|
||||
def author_reader():
|
||||
|
||||
contributor_file = open('contributor_database')
|
||||
|
||||
author_database = {}
|
||||
|
||||
contributor_db = contributor_file.read().split('\n')
|
||||
contributor_db = [contributor for contributor in contributor_db if contributor.strip() != '']
|
||||
for contributor_data_db in contributor_db:
|
||||
snippetName,contributor_data = contributor_data_db.split(':')
|
||||
author = contributor_data.split(',')[0]
|
||||
contributors = contributor_data.split(',')
|
||||
author = re.sub('(\[[\w\s]+\]\()\@(\w+)\)','\g<1>https://www.github.com/\g<2>)',author.strip())
|
||||
contributors = [re.sub('(\[[\w\s]+\]\()\@(\w+)\)','\g<1>https://www.github.com/\g<2>)',contributor) for contributor in contributors]
|
||||
author_database[snippetName] = (author,contributors)
|
||||
return author_database
|
||||
def tagger():
|
||||
snippet_files = [snippet.replace('.md','')for snippet in os.listdir('snippets')]
|
||||
|
||||
tag_database_file = open('tag_database')
|
||||
|
||||
@ -40,11 +55,13 @@ def read_snippets():
|
||||
for snippet_file in snippet_files:
|
||||
snippets.append(snippet(f'snippets/{snippet_file}'))
|
||||
return snippets
|
||||
|
||||
|
||||
def read_readme_start():
|
||||
with open('static-part/readme-start.md') as f:
|
||||
with open('static-parts/readme-start.md') as f:
|
||||
readme_start = f.read()
|
||||
return readme_start
|
||||
def read_readme_end():
|
||||
with open('static-part/readme-end.md') as f:
|
||||
with open('static-parts/readme-end.md') as f:
|
||||
readme_end = f.read()
|
||||
return readme_end
|
||||
|
||||
Reference in New Issue
Block a user