From 1d9b2eb9e1128ad078f8a0cdfcbabc5190632aea Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Wed, 24 Oct 2018 18:28:23 -0400 Subject: [PATCH] Working on automating doc creation. --- Autocomplete.md | 42 ++++++++++++++++++++++++++++++++++++++++++ gen_docs.py | 36 ++++++++++++++++++++++++++++++++++++ test.md | 23 +++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 Autocomplete.md create mode 100644 gen_docs.py create mode 100644 test.md diff --git a/Autocomplete.md b/Autocomplete.md new file mode 100644 index 0000000..34b3f35 --- /dev/null +++ b/Autocomplete.md @@ -0,0 +1,42 @@ +# **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 (`{Class_name}().scryfallJson`). +|cards/autocomplete| +|Get a list of potential autocompletion phrases.| + +## Args + +| arg | 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.| + +## Raises + +| arg | description | +|:---:|:---:| +|Exception: If the 'q' parameter is not provided.| +|Exception: If the object returned is an error.| + +## Example usage + +| arg | description | +|:---:|:---:| +|>>> auto = scrython.cards.Autocomplete(q="Thal")| +|>>> auto.total_items()| \ No newline at end of file diff --git a/gen_docs.py b/gen_docs.py new file mode 100644 index 0000000..f5aae01 --- /dev/null +++ b/gen_docs.py @@ -0,0 +1,36 @@ +import sys +import scrython +from scrython import * +import re + +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 (`{Class_name}().scryfallJson`).""" + +for _class in scrython.__all__: + + 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: + # 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 + elif re.findall(r'[\w]+\s\(.+\):', token): + if 'Defaults' in token: + f.write(token) + else: + f.write('\n|{}'.format(token)) + else: + f.write('\n|{}|'.format(token)) + # r'[\w]+\s\(.+\):' Matches anything that's a described parameter + # r'[A-Z][a-z](.*)' Matches section titles + break diff --git a/test.md b/test.md new file mode 100644 index 0000000..fff2959 --- /dev/null +++ b/test.md @@ -0,0 +1,23 @@ +# **class** `{Class_name}()` + +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 (`{Class_name}().scryfallJson`). + +## Args + +|arg|description| +|:---:|:---:| +|{arg} ({type})|{description}| + +## Raises + +|exception type|reason| +|:---:|:---:| +|{Exception}|{reason}| + +## Example usage + +``` + {Examples} +``` \ No newline at end of file