Getting closer with this
This commit is contained in:
parent
d99a786642
commit
ff51762b8a
58
gen_docs.py
58
gen_docs.py
|
@ -3,36 +3,48 @@ import scrython
|
||||||
from scrython import *
|
from scrython import *
|
||||||
import re
|
import re
|
||||||
|
|
||||||
for _class in scrython.__all__:
|
def format_args(string):
|
||||||
|
start = '|arg|type|description|\n|:---:|:---:|:---:|'
|
||||||
|
|
||||||
|
names = re.findall(r'(\w*\s\([\w,\s]*\):)', string)
|
||||||
|
|
||||||
|
for _class in scrython.__all__:
|
||||||
|
|
||||||
intro = """These docs will likely not be as detailed as the official Scryfall Documentation, and you should reference that for more information.
|
intro = """These docs will likely not be as detailed as the official Scryfall Documentation, and you should reference that for more information.
|
||||||
|
|
||||||
>In the event that a key isn't found or has been changed, you can access the full JSON output with the `scryfallJson` variable (`{}().scryfallJson`).
|
>In the event that a key isn't found or has been changed, you can access the full JSON output with the `scryfallJson` variable (`{}().scryfallJson`).
|
||||||
""".format(eval(_class).__name__)
|
""".format(eval(_class).__name__)
|
||||||
|
|
||||||
match = list(filter(None, (token.strip() for token in re.findall(r'[^\n]*', eval(_class).__doc__))))
|
class_docstring = repr(re.sub(r'\n+', '', eval(_class).__doc__)) # removes newlines
|
||||||
|
|
||||||
with open('{}.md'.format(eval(_class).__name__), 'w') as f:
|
remove_extra_spaces = re.sub(' +', ' ', class_docstring)
|
||||||
f.write('# **class** `{}()`\n'.format(eval(_class).__name__))
|
|
||||||
f.write(intro)
|
|
||||||
for token in match:
|
|
||||||
# Match section header
|
|
||||||
if re.findall(r'[A-Z][a-z].*:', token) and ':' in re.findall(r':.*', token):
|
|
||||||
f.write('\n\n## {}\n\n'.format(token.replace(':', '')))
|
|
||||||
if 'Example' in token:
|
|
||||||
f.write()
|
|
||||||
else:
|
|
||||||
f.write('| arg | description |\n|:---:|:---:|')
|
|
||||||
|
|
||||||
# Match args description
|
args = re.findall(r'(?<=Args:)(.*)(?=Returns:)', remove_extra_spaces)[0]
|
||||||
elif re.findall(r'[\w]+\s\(.+\):', token):
|
format_args(args)
|
||||||
if 'Defaults' in token:
|
|
||||||
f.write(token)
|
returns = re.findall(r'(?<=Returns:)(.*)(?=Raises:)', remove_extra_spaces)[0]
|
||||||
else:
|
|
||||||
f.write('\n|{}'.format(token))
|
raises = re.findall(r'(?<=Raises:)(.*)(?=Examples:)', remove_extra_spaces)[0]
|
||||||
else:
|
|
||||||
f.write('\n|{}|'.format(token))
|
examples = re.findall(r'(?<=Examples:)(.*)', remove_extra_spaces)[0]
|
||||||
# r'[\w]+\s\(.+\):' Matches anything that's a described parameter
|
|
||||||
# r'[A-Z][a-z](.*)' Matches section titles
|
# match = list(filter(None, (token.strip() for token in re.findall(r'[^\n]*', eval(_class).__doc__))))
|
||||||
|
|
||||||
|
# with open('{}.md'.format(eval(_class).__name__), 'w') as f:
|
||||||
|
# f.write('# **class** `{}()`\n'.format(eval(_class).__name__))
|
||||||
|
# f.write(intro)
|
||||||
|
# for token in match:
|
||||||
|
# if re.findall(r'[A-Z][a-z].*:', token) and ':' in re.findall(r':.*', token): # Match section header
|
||||||
|
# f.write('\n\n## {}\n\n'.format(token.replace(':', '')))
|
||||||
|
# if 'Example' in token:
|
||||||
|
# f.write(token)
|
||||||
|
# else:
|
||||||
|
# f.write('| arg | description |\n|:---:|:---:|')
|
||||||
|
# elif re.findall(r'[\w]+\s\(.+\):', token): # Match args description
|
||||||
|
# if 'Defaults' in token:
|
||||||
|
# f.write(token)
|
||||||
|
# else:
|
||||||
|
# f.write('\n|{}|'.format(token))
|
||||||
|
# else:
|
||||||
|
# f.write('\n|{}|'.format(token))
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue