-
Notifications
You must be signed in to change notification settings - Fork 10
Python Pypresence better integration #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
StratusFearMe21
wants to merge
6
commits into
cniw:master
Choose a base branch
from
StratusFearMe21:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0ea5638
Update main.lua
StratusFearMe21 1299db4
Update python-pypresence.py
StratusFearMe21 5bbfc64
Update main.lua
StratusFearMe21 5641ed1
Change testfile.txt filename
StratusFearMe21 f69f48e
Change filename testfile.txt
StratusFearMe21 648b743
Update main.lua
StratusFearMe21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,42 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import signal | ||
| from pathlib import Path | ||
| import sys | ||
| import time | ||
| import os | ||
| import pypresence | ||
|
|
||
| home = str(Path.home()) | ||
| print(home) | ||
| print("start") | ||
| client_id = "448016723057049601" | ||
| pid = 9999 | ||
|
|
||
| todo = str(sys.argv[1]) if len(sys.argv) > 1 else "shutdown" | ||
| state = str(sys.argv[2]) if len(sys.argv) > 2 else "state = (Idle)" | ||
| details = str(sys.argv[3]) if len(sys.argv) > 3 else "details = No file" | ||
| start = int(sys.argv[4]) if len(sys.argv) > 4 else int(time.time()) | ||
| end = int(sys.argv[5]) if len(sys.argv) > 5 else int(time.time() + 60) | ||
| large_image = str(sys.argv[6]) if len(sys.argv) > 6 else "mpv" | ||
| large_text = str(sys.argv[7]) if len(sys.argv) > 7 else "large_text = mpv Media Player" | ||
| small_image = str(sys.argv[8]) if len(sys.argv) > 8 else "player_stop" | ||
| small_text = str(sys.argv[9]) if len(sys.argv) > 9 else "small_text = Idle" | ||
| periodic_timer = int(sys.argv[10]) if len(sys.argv) > 10 else 15 | ||
|
|
||
| TimeoutHandler = Exception | ||
|
|
||
| def timeout_handler(num, stack): | ||
| raise TimeoutHandler | ||
|
|
||
| try: | ||
| RPC = pypresence.Presence(client_id) | ||
| RPC.connect() | ||
| #print("pypresence: RPC connected") | ||
| signal.signal(signal.SIGALRM, timeout_handler) | ||
| signal.alarm(periodic_timer) | ||
| RPC = pypresence.Presence(client_id) | ||
| RPC.connect() | ||
| print("pypresence: RPC connected") | ||
| while True: | ||
| time.sleep(4) | ||
| pid = 9999 | ||
| file = open("/dev/shm/testfile.txt").read().splitlines() | ||
| todo = str(file[1]) if len(file) > 1 else "shutdown" | ||
| state = str(file[2]) if len(file) > 2 else "state = (Idle)" | ||
| details = str(file[3]) if len(file) > 3 else "details = No file" | ||
| start = int(file[4]) if len(file) > 4 else int(time.time()) | ||
| end = int(file[5]) if len(file) > 5 else int(time.time() + 60) | ||
| large_image = str(file[6]) if len(file) > 6 else "mpv" | ||
| large_text = str(file[7]) if len(file) > 7 else "large_text = mpv Media Player" | ||
| small_image = str(file[8]) if len(file) > 8 else "player_stop" | ||
| small_text = str(file[9]) if len(file) > 9 else "small_text = Idle" | ||
| periodic_timer = int(file[10]) if len(file) > 10 else 15 | ||
| if todo == "shutdown": | ||
| RPC.clear() | ||
| #print("pypresence: RPC cleared") | ||
| print("pypresence: RPC cleared") | ||
| RPC.close() | ||
| #print("pypresence: RPC closed") | ||
| print("pypresence: RPC closed") | ||
| os.system('rm -rf "/dev/shm/testfile.txt"') | ||
| sys.exit() | ||
| elif todo == "idle": | ||
| RPC.update(state=state, details=details, start=start, large_image=large_image, large_text=large_text, small_image=small_image, small_text=small_text) | ||
| #print("pypresence: RPC updated.") | ||
| time.sleep(periodic_timer) | ||
| print("pypresence: RPC updated.") | ||
| elif todo == "not-idle": | ||
| RPC.update(state=state, details=details, end=end, large_image=large_image, large_text=large_text, small_image=small_image, small_text=small_text) | ||
| #print("pypresence: RPC updated") | ||
| time.sleep(periodic_timer) | ||
| except (KeyboardInterrupt, SystemExit): | ||
| #print(" interupt: KeyboardInterrupt|SystemExit)") | ||
| sys.exit() | ||
| except (BrokenPipeError, IOError): | ||
| #print(" interupt: BrokenPipeError|IOError") | ||
| sys.exit() | ||
| except (TimeoutHandler): | ||
| #print(" interupt: TimeoutHandler") | ||
| sys.exit() | ||
| except: | ||
| sys.exit() | ||
| print("pypresence: RPC updated") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.