audiothek

alternative frontend for ardaudiothek.de  https://audiothek.ce9e.org/
git clone https://git.ce9e.org/audiothek.git

commit
476189072ab3657f035c71d3c501488ba3c06112
parent
e9d75869afd2162c2cbfed6b2d45ea6d53182a8f
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-02-14 07:20
add script to download schema

Diffstat

A introspect.py 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1 files changed, 93 insertions, 0 deletions


diff --git a/introspect.py b/introspect.py

@@ -0,0 +1,93 @@
   -1     1 import json
   -1     2 import asyncio
   -1     3 
   -1     4 import aiohttp
   -1     5 
   -1     6 QUERY = """
   -1     7 query IntrospectionQuery {
   -1     8     __schema {
   -1     9         queryType { name }
   -1    10         mutationType { name }
   -1    11         subscriptionType { name }
   -1    12         types { ...FullType }
   -1    13         directives {
   -1    14             name
   -1    15             description
   -1    16             locations
   -1    17             args { ...InputValue }
   -1    18         }
   -1    19     }
   -1    20 }
   -1    21 fragment FullType on __Type {
   -1    22     kind
   -1    23     name
   -1    24     description
   -1    25     fields(includeDeprecated: true) {
   -1    26         name
   -1    27         description
   -1    28         args { ...InputValue }
   -1    29         type { ...TypeRef }
   -1    30         isDeprecated
   -1    31         deprecationReason
   -1    32     }
   -1    33     inputFields { ...InputValue }
   -1    34     interfaces { ...TypeRef }
   -1    35     enumValues(includeDeprecated: true) {
   -1    36         name
   -1    37         description
   -1    38         isDeprecated
   -1    39         deprecationReason
   -1    40     }
   -1    41     possibleTypes { ...TypeRef }
   -1    42 }
   -1    43 fragment InputValue on __InputValue {
   -1    44     name
   -1    45     description
   -1    46     type { ...TypeRef }
   -1    47     defaultValue
   -1    48 }
   -1    49 fragment TypeRef on __Type {
   -1    50     kind name ofType {
   -1    51         kind name ofType {
   -1    52             kind name ofType {
   -1    53                 kind name ofType {
   -1    54                     kind name ofType {
   -1    55                         kind name ofType {
   -1    56                             kind name ofType {
   -1    57                                 kind name
   -1    58                             }
   -1    59                         }
   -1    60                     }
   -1    61                 }
   -1    62             }
   -1    63         }
   -1    64     }
   -1    65 }
   -1    66 """
   -1    67 
   -1    68 
   -1    69 async def main():
   -1    70     url = 'https://api.ardaudiothek.de/graphql'
   -1    71     params = {
   -1    72         'query': QUERY,
   -1    73         'variables': '{}',
   -1    74     }
   -1    75     async with aiohttp.ClientSession() as session:
   -1    76         async with session.get(url, params=params) as response:
   -1    77             response.raise_for_status()
   -1    78             data = await response.json()
   -1    79 
   -1    80     short = {}
   -1    81     for t in data['data']['__schema']['types']:
   -1    82         short[t['name']] = {
   -1    83             'kind': t['kind'],
   -1    84             'description': t['description'],
   -1    85             'fields': {
   -1    86                 f['name']: f['type']['name'] for f in (t['fields'] or [])
   -1    87             },
   -1    88         }
   -1    89     print(json.dumps(short, indent=2))
   -1    90 
   -1    91 
   -1    92 if __name__ == '__main__':
   -1    93     asyncio.run(main())