2018-10-24 22:28:23 +00:00
|
|
|
import sys
|
|
|
|
import scrython
|
|
|
|
import re
|
2018-10-28 03:16:33 +00:00
|
|
|
from scrython import *
|
|
|
|
from types import FunctionType
|
2018-10-24 22:28:23 +00:00
|
|
|
|
2018-10-28 02:24:27 +00:00
|
|
|
def format_args(string, f):
|
2018-10-28 02:56:57 +00:00
|
|
|
f.write('\n## Args\n\n|arg|type|description|\n|:---:|:---:|:---:|\n')
|
2018-10-28 01:40:21 +00:00
|
|
|
|
|
|
|
arg_list = re.findall(r'(\w*\s*\(\w+[,\s\w]{1,}\):[\w\s\'\\`,.]*[^\w\s\(])', string)
|
|
|
|
|
|
|
|
for arg in arg_list:
|
|
|
|
arg_name = re.findall(r'[^\s]*', arg)[0]
|
|
|
|
|
|
|
|
description = re.findall(r'(?<=:\s)(.*)', arg)[0]
|
|
|
|
|
|
|
|
type_and_optional = re.findall(r'(?<=\()\w+[,\s\w]+(?=\))', arg)[0]
|
|
|
|
|
|
|
|
if len(type_and_optional) > 1:
|
2018-10-28 02:54:47 +00:00
|
|
|
f.write('|{}|{}|{}|\n'.format(arg_name, type_and_optional, description))
|
2018-10-28 01:40:21 +00:00
|
|
|
|
|
|
|
else:
|
2018-10-28 02:54:47 +00:00
|
|
|
f.write('|{}|{}|{}|\n'.format(arg_name, type_and_optional, description))
|
2018-10-28 02:24:27 +00:00
|
|
|
|
2018-10-28 02:54:47 +00:00
|
|
|
def format_returns(string, f):
|
|
|
|
f.write('\n## Returns\n{}\n'.format(string.strip()))
|
2018-10-28 02:24:27 +00:00
|
|
|
|
2018-10-28 02:54:47 +00:00
|
|
|
def format_raises(string, f):
|
2018-10-28 02:24:27 +00:00
|
|
|
|
2018-10-28 02:56:57 +00:00
|
|
|
f.write('\n## Raises\n\n|exception type|reason|\n|:---:|:---:|\n')
|
2018-10-28 02:24:27 +00:00
|
|
|
|
|
|
|
exception_list = re.findall(r'\w+:[\w\s\\\']+[^\s\w:]', string)
|
|
|
|
|
|
|
|
for exception in exception_list:
|
|
|
|
exception_name = re.findall(r'[^:]*', exception)[0]
|
|
|
|
|
|
|
|
exception_description = re.findall(r'(?<=:\s)([\w\s\.\'\\]*)', exception)[0]
|
|
|
|
|
2018-10-28 02:54:47 +00:00
|
|
|
f.write('|{}|{}|\n'.format(exception_name, exception_description))
|
2018-10-24 22:28:23 +00:00
|
|
|
|
2018-10-28 02:54:47 +00:00
|
|
|
def format_examples(string, f):
|
2018-10-24 22:28:23 +00:00
|
|
|
|
2018-10-28 02:54:47 +00:00
|
|
|
example_list = re.findall(r'>{3}[\s\w=.("+:,)]+', string)
|
2018-10-26 01:35:36 +00:00
|
|
|
|
2018-10-28 02:54:47 +00:00
|
|
|
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__)
|
2018-10-24 22:28:23 +00:00
|
|
|
|
2018-10-26 21:23:50 +00:00
|
|
|
class_docstring = repr(re.sub(r'\n+', '', eval(_class).__doc__)) # removes newlines
|
|
|
|
|
|
|
|
remove_extra_spaces = re.sub(' +', ' ', class_docstring)
|
|
|
|
|
|
|
|
args = re.findall(r'(?<=Args:)(.*)(?=Returns:)', remove_extra_spaces)[0]
|
|
|
|
|
|
|
|
returns = re.findall(r'(?<=Returns:)(.*)(?=Raises:)', remove_extra_spaces)[0]
|
|
|
|
|
|
|
|
raises = re.findall(r'(?<=Raises:)(.*)(?=Examples:)', remove_extra_spaces)[0]
|
|
|
|
|
|
|
|
examples = re.findall(r'(?<=Examples:)(.*)', remove_extra_spaces)[0]
|
|
|
|
|
2018-10-28 03:16:33 +00:00
|
|
|
functions = [x for x, y in eval(_class).__dict__.items() if type(y) == FunctionType and y.__name__ != '__init__']
|
2018-10-28 02:54:47 +00:00
|
|
|
|
2018-10-28 03:16:33 +00:00
|
|
|
# with open('{}.md'.format(_class), 'w') as f:
|
|
|
|
# f.write('# **class** `{}()`\n'.format(_class))
|
2018-10-26 21:23:50 +00:00
|
|
|
# f.write(intro)
|
2018-10-28 03:16:33 +00:00
|
|
|
# format_args(args, f)
|
|
|
|
# format_returns(returns, f)
|
|
|
|
# format_raises(raises, f)
|
|
|
|
# format_examples(examples, f)
|
|
|
|
|
2018-10-24 22:28:23 +00:00
|
|
|
break
|