Script now formats class strings
This commit is contained in:
parent
bff6ea4d27
commit
026bf18be9
|
@ -0,0 +1,29 @@
|
|||
# **class** `Autocomplete()`
|
||||
|
||||
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 (`Autocomplete().scryfallJson`).
|
||||
|
||||
## Args
|
||||
|
||||
|arg|type|description|
|
||||
|:---:|:---:|:---:||q|string|The query of the autocompletion.|
|
||||
|format|string, optional|Defaults to \'json\'. Returns data in the specified method.|
|
||||
|face|string, optional|Defaults to empty string. If you\'re using the `image` format, this will specify if you want the front or back face.|
|
||||
|version|string, optional|Defaults to empty string. If you\'re using the `image` format, this will specify if you want the small, normal, large, etc version of the image.|
|
||||
|pretty|string, optional|Defaults to empty string. Returns a prettier version of the json object. Note that this may break functionality with Scrython.|
|
||||
|
||||
## Returns
|
||||
N/A
|
||||
|
||||
## Raises
|
||||
|
||||
|exception type|reason|
|
||||
|:---:|:---:||Exception|If the \'q\' parameter is not provided.|
|
||||
|Exception|If the object returned is an error.|
|
||||
|
||||
## Examples
|
||||
```
|
||||
>>> auto = scrython.cards.Autocomplete(q="Thal")
|
||||
>>> auto.total_items()
|
||||
```
|
42
gen_docs.py
42
gen_docs.py
|
@ -4,7 +4,7 @@ from scrython import *
|
|||
import re
|
||||
|
||||
def format_args(string, f):
|
||||
f.write('|arg|type|description|\n|:---:|:---:|:---:|')
|
||||
f.write('\n## Args\n\n|arg|type|description|\n|:---:|:---:|:---:|')
|
||||
|
||||
arg_list = re.findall(r'(\w*\s*\(\w+[,\s\w]{1,}\):[\w\s\'\\`,.]*[^\w\s\(])', string)
|
||||
|
||||
|
@ -16,19 +16,17 @@ def format_args(string, f):
|
|||
type_and_optional = re.findall(r'(?<=\()\w+[,\s\w]+(?=\))', arg)[0]
|
||||
|
||||
if len(type_and_optional) > 1:
|
||||
f.write('|{}|{}|{}|'.format(arg_name, type_and_optional, description))
|
||||
f.write('|{}|{}|{}|\n'.format(arg_name, type_and_optional, description))
|
||||
|
||||
else:
|
||||
f.write('|{}|{}|{}|'.format(arg_name, type_and_optional, description))
|
||||
f.write('|{}|{}|{}|\n'.format(arg_name, type_and_optional, description))
|
||||
|
||||
def format_returns(string):
|
||||
if string == 'N/A':
|
||||
return
|
||||
def format_returns(string, f):
|
||||
f.write('\n## Returns\n{}\n'.format(string.strip()))
|
||||
|
||||
def format_raises(string):
|
||||
def format_raises(string, f):
|
||||
|
||||
print('## Raises\n')
|
||||
print('|exception type|reason|\n|:---:|:---:|')
|
||||
f.write('\n## Raises\n\n|exception type|reason|\n|:---:|:---:|')
|
||||
|
||||
exception_list = re.findall(r'\w+:[\w\s\\\']+[^\s\w:]', string)
|
||||
|
||||
|
@ -37,11 +35,19 @@ def format_raises(string):
|
|||
|
||||
exception_description = re.findall(r'(?<=:\s)([\w\s\.\'\\]*)', exception)[0]
|
||||
|
||||
print('|{}|{}|'.format(exception_name, exception_description))
|
||||
f.write('|{}|{}|\n'.format(exception_name, exception_description))
|
||||
|
||||
for _class in scrython.__all__[7:]:
|
||||
def format_examples(string, f):
|
||||
|
||||
intro = """These docs will likely not be as detailed as the official Scryfall Documentation, and you should reference that for more information.
|
||||
example_list = re.findall(r'>{3}[\s\w=.("+:,)]+', string)
|
||||
|
||||
f.write('\n## Examples\n')
|
||||
f.write('```\n{}\n```'.format('\n'.join(example_list)))
|
||||
|
||||
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.
|
||||
|
||||
>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__)
|
||||
|
@ -55,10 +61,20 @@ for _class in scrython.__all__[7:]:
|
|||
returns = re.findall(r'(?<=Returns:)(.*)(?=Raises:)', remove_extra_spaces)[0]
|
||||
|
||||
raises = re.findall(r'(?<=Raises:)(.*)(?=Examples:)', remove_extra_spaces)[0]
|
||||
format_raises(raises)
|
||||
|
||||
examples = re.findall(r'(?<=Examples:)(.*)', remove_extra_spaces)[0]
|
||||
|
||||
with open('{}.md'.format(_class), 'w') as f:
|
||||
f.write('# **class** `{}()`\n'.format(_class))
|
||||
f.write(intro)
|
||||
format_args(args, f)
|
||||
format_returns(returns, f)
|
||||
format_raises(raises, f)
|
||||
format_examples(examples, f)
|
||||
|
||||
break
|
||||
|
||||
|
||||
# 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:
|
||||
|
|
Loading…
Reference in New Issue