Joe Gregorio | afc45f2 | 2011-02-20 16:11:28 -0500 | [diff] [blame^] | 1 | import os |
| 2 | import pydoc |
| 3 | import re |
| 4 | |
| 5 | from apiclient.discovery import build |
| 6 | |
| 7 | BASE = 'docs/dyn' |
| 8 | |
| 9 | APIS = [ |
| 10 | ('buzz', 'v1'), |
| 11 | ('moderator', 'v1'), |
| 12 | ('latitude', 'v1'), |
| 13 | ('customsearch', 'v1'), |
| 14 | ('diacritize', 'v1'), |
| 15 | ('translate', 'v2'), |
| 16 | ('prediction', 'v1.1'), |
| 17 | ('shopping', 'v1'), |
| 18 | ('urlshortener', 'v1'), |
| 19 | ] |
| 20 | |
| 21 | def document(resource, path): |
| 22 | print path |
| 23 | collections = [] |
| 24 | for name in dir(resource): |
| 25 | if not "_" in name and callable(getattr(resource, name)) and hasattr( |
| 26 | getattr(resource, name), '__is_resource__'): |
| 27 | collections.append(name) |
| 28 | |
| 29 | obj, name = pydoc.resolve(type(resource)) |
| 30 | page = pydoc.html.page( |
| 31 | pydoc.describe(obj), pydoc.html.document(obj, name)) |
| 32 | |
| 33 | for name in collections: |
| 34 | page = re.sub('strong>(%s)<' % name, r'strong><a href="%s">\1</a><' % (path + name + ".html"), page) |
| 35 | for name in collections: |
| 36 | document(getattr(resource, name)(), path + name + ".") |
| 37 | |
| 38 | f = open(os.path.join(BASE, path + 'html'), 'w') |
| 39 | f.write(page) |
| 40 | f.close() |
| 41 | |
| 42 | def document_api(name, version): |
| 43 | service = build(name, version) |
| 44 | document(service, '%s.%s.' % (name, version)) |
| 45 | |
| 46 | if __name__ == '__main__': |
| 47 | for name, version in APIS: |
| 48 | document_api(name, version) |
| 49 | |