Created
August 8, 2022 17:01
-
-
Save malfet/1b67a0856384429bfd7fb0149f4b88a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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