-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpgraph.py
36 lines (28 loc) · 1.01 KB
/
pgraph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import logging as log
from addict import Dict
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
from jinja2 import Template
import config
def query(name, **kwargs):
url = "https://api.github.com/graphql"
api_token = config.get_value("token")
transport = RequestsHTTPTransport(
url=url,
use_json=True,
headers={
"Authorization": "Bearer %s" % api_token,
"Accept": "application/vnd.github.vixen-preview+json",
},
)
log.debug(f"Calling query {name}.graphql with token starting {api_token[0:4]}")
client = Client(transport=transport, fetch_schema_from_transport=False)
queries = {}
for filename in os.listdir("query"):
with open(f"query/{filename}") as query_file:
queries[filename.split(".")[0]] = query_file.read()
query_template = Template(queries[name])
full_query = query_template.render(**kwargs)
query = gql(full_query)
return Dict(client.execute(query))