revert if needed, Directly sending json info to plugin

This commit is contained in:
Roy 2024-02-27 19:35:48 -08:00 committed by GitHub
parent d2f6991d44
commit 9890c629c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1024,11 +1024,15 @@ if new_shortcuts_added or shortcuts_updated:
# Assuming 'games' is a list of game dictionaries # Assuming 'games' is a list of game dictionaries
games = [shortcut for shortcut in shortcuts['shortcuts'].values()] games = [shortcut for shortcut in shortcuts['shortcuts'].values()]
# Create the path to the output file sys.path.append(f"{logged_in_home}/homebrew") # Add the directory containing aiohttp to the Python path
output_file_path = f"{logged_in_home}/.config/systemd/user/NSLGameScanner_output.log" import aiohttp
import asyncio
# Open the output file in write mode async def send_data():
with open(output_file_path, 'w') as output_file: # Create a session
async with aiohttp.ClientSession() as session:
# Connect to the WebSocket
async with session.ws_connect('http://localhost:8765') as ws:
for game in games: for game in games:
# Skip if 'appname' or 'exe' is None # Skip if 'appname' or 'exe' is None
if game.get('appname') is None or game.get('exe') is None: if game.get('appname') is None or game.get('exe') is None:
@ -1045,11 +1049,10 @@ if new_shortcuts_added or shortcuts_updated:
'GameID': game.get('GameID', "default_game_id") # Use a default value if game_id is not defined 'GameID': game.get('GameID', "default_game_id") # Use a default value if game_id is not defined
} }
# Print the shortcut information in JSON format # Send the JSON data to the WebSocket
message = json.dumps(shortcut_info) await ws.send_json(shortcut_info)
print(message, flush=True) # Print to stdout
# Print the shortcut information to the output file # Run the send_data coroutine
print(message, file=output_file, flush=True) asyncio.run(send_data())
print("All finished!") print("All finished!")