39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import requests
|
|
import time
|
|
import json
|
|
from pypresence import Presence
|
|
from pypresence.types import ActivityType, StatusDisplayType
|
|
|
|
client_id = "1439626657978646559"
|
|
RPC = Presence(client_id)
|
|
RPC.connect()
|
|
|
|
def get_game_data():
|
|
try:
|
|
response = requests.get('https://127.0.0.1:2999/liveclientdata/allgamedata',
|
|
verify=False,
|
|
timeout=2)
|
|
return response.json()
|
|
except requests.exceptions.RequestException:
|
|
return None
|
|
|
|
while True:
|
|
data = get_game_data()
|
|
|
|
if data is None:
|
|
print("League isn't running or no game active")
|
|
time.sleep(3) # Poll every 3 seconds, reasonable limit for riot api
|
|
continue
|
|
|
|
# Parse and do stuff with data here
|
|
game_time = data['gameData']['gameTime']
|
|
print(f"Game time: {game_time:.0f}s")
|
|
|
|
# Show as "Listening to" instead of "Playing"
|
|
RPC.update(
|
|
activity_type=ActivityType.PLAYING,
|
|
details="My Favorite Song",
|
|
state="By My Favorite Artist"
|
|
)
|
|
|
|
time.sleep(15) # Poll every 15 seconds (discord update limit) |