Skip to content

Instantly share code, notes, and snippets.

@malfet
Created August 8, 2022 17:01
Show Gist options
  • Save malfet/1b67a0856384429bfd7fb0149f4b88a7 to your computer and use it in GitHub Desktop.
Save malfet/1b67a0856384429bfd7fb0149f4b88a7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
GH_GET_VIEWER_LOGIN = """
query {
viewer {
login
}
}
"""
def gh_graphql(query):
import os
import json
from urllib.request import urlopen, Request
token = os.getenv("GITHUB_TOKEN")
headers = {"Accept": "application/vnd.github.v3+json", "Authorization": f"token {token}"}
data = json.dumps({"query": query}).encode()
with urlopen(Request("https://api.github.com/graphql", data=data, headers=headers)) as conn:
return json.load(conn)
if __name__ == "__main__":
print(gh_graphql(GH_GET_VIEWER_LOGIN))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment