forked from XtremePrime/RetroAchievements-Discord-Presence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRANes.py
58 lines (48 loc) · 1.9 KB
/
RANes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# XtremePrime 2024
# -- You will need to setup a discord application for this in order to work. To do so, follow the instructions in the README.md
# -- Please note: This will not be 100% accurate as it only uses latest data from your retro achievements page
import io
import requests
import sys
import time
from pypresence import Presence
# The first argument of your python call should be your Username, then your API_KEY, then your Discord Application Client ID
# Ex:
# > python RANes.py AverageUser 0X0X0X0X0X0X0X0X 123456789
USERNAME=str(sys.argv[1])
API_KEY=str(sys.argv[2])
RPC_CLIENT_ID = str(sys.argv[3])
profile_url = "https://retroachievements.org/API/API_GetUserProfile.php?u={0}&y={1}&z={2}".format(USERNAME, API_KEY, USERNAME)
print(profile_url)
RPC = Presence(RPC_CLIENT_ID)
print(">Connecting to Discord App...")
RPC.connect()
print(">Connected")
status = True
while(status):
print(">GET profile game activity...")
response = requests.get(profile_url)
if response.status_code == 200:
data = response.json()
print(">Result: {0}".format(data["RichPresenceMsg"]))
game_params = "?z={0}&y={1}&i={2}".format(USERNAME, API_KEY, data["LastGameID"])
game_url = "{0}?{1}".format("https://retroachievements.org/API/API_GetGame.php", game_params)
print(">GET game data...")
game_response = requests.get(game_url)
if game_response.status_code == 200:
game_data = game_response.json()
print(">Result: {0}".format(game_data["GameTitle"]))
else:
print("Failed to fetch profile data:", response.status_code)
status = False
break;
else:
print("Failed to fetch game data:", game_response.status_code)
status = False
break;
RPC.update(
state=data["RichPresenceMsg"],
details=game_data["GameTitle"],
)
print(">Sleeping...")
time.sleep(30)