Skip to content

Instantly share code, notes, and snippets.

@terminalcommandnewsletter
Created December 14, 2023 16:54
Show Gist options
  • Save terminalcommandnewsletter/c0530f2a832463391af118ee4b766bae to your computer and use it in GitHub Desktop.
Save terminalcommandnewsletter/c0530f2a832463391af118ee4b766bae to your computer and use it in GitHub Desktop.
GitHub Status Live Update for GNOME Wayland
token = "Add your own token here"
import os, time, requests
emojis = {"code": ":large_blue_circle:", "firefox": ":fox_face:", "terminator": ":red_circle:"} # Add some more here
def get_emoji(window_name):
if window_name.lower() in list(emojis.keys()): return emojis[window_name.lower()]
return ":question:"
if "Add your own token here" in token:
print("Replace the token variable on line 1 with your token!")
exit(1)
while True:
window_name = os.popen("gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\)[`gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\).findIndex\(a\=\>a.meta_window.has_focus\(\)===true\) | cut -d\"'\" -f 2`].get_meta_window\(\).get_wm_class\(\) | cut -d'\"' -f 2").read().strip() # Taken from https://gist.github.com/rbreaves/257c3edfa301786e66e964d7ac036269
graphql_query = """
mutation {
changeUserStatus(input: { emoji: \"""" + get_emoji(window_name) + """", message: "Using """ + window_name + """!" }) {
status {
emoji
message
}
}
}
"""
api_url = "https://api.github.com/graphql"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
}
payload = {"query": graphql_query}
response = requests.post(api_url, headers=headers, json=payload)
print("DEBUG: " + response.text)
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment