final version
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -162,4 +162,5 @@ cython_debug/
|
||||
|
||||
#project specific
|
||||
|
||||
websocket*
|
||||
websocket*
|
||||
test.json
|
||||
27
main.py
27
main.py
@@ -1,15 +1,36 @@
|
||||
import websocket
|
||||
import datetime
|
||||
import json
|
||||
from colr import color
|
||||
|
||||
def on_message(ws, message):
|
||||
print("Data received! Writing it to a file")
|
||||
# Generate a timestamp for the filename
|
||||
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||
filename = f"websocket_{timestamp}.dict"
|
||||
|
||||
with open(filename, "w") as file:
|
||||
file.write(message)
|
||||
print(f"Data written to file {filename}\n")
|
||||
|
||||
data = json.loads(message)
|
||||
SKIN_BUDDY_ID = "ad508aeb-44b7-46bf-f923-959267483e78"
|
||||
|
||||
for player_id, player in data['Players'].items():
|
||||
for weapon_id, weapon in player['Weapons'].items():
|
||||
if 'skin_buddy' in weapon and weapon['skin_buddy'] == SKIN_BUDDY_ID:
|
||||
if player['Team'] == "Blue":
|
||||
|
||||
print(color(f"Found RGB in player: {player['Name']}", fore='blue', style='bright'))
|
||||
print("Weapon:", weapon['weapon'])
|
||||
print("Skin:", weapon['skinDisplayName'])
|
||||
print()
|
||||
|
||||
if player['Team'] == "Red":
|
||||
|
||||
print(color(f"Found RGB in player: {player['Name']}", fore='red', style='bright'))
|
||||
print("Weapon:", weapon['weapon'])
|
||||
print("Skin:", weapon['skinDisplayName'])
|
||||
print()
|
||||
|
||||
def on_error(ws, error):
|
||||
print(f"Error: {error}")
|
||||
@@ -21,7 +42,7 @@ def on_open(ws):
|
||||
print("Connection established. Waiting for data...\n")
|
||||
|
||||
def main():
|
||||
websocket_url = "ws://localhost:1100" # Replace with the correct WebSocket URL
|
||||
websocket_url = "ws://localhost:1100"
|
||||
ws = websocket.WebSocketApp(websocket_url,
|
||||
on_message=on_message,
|
||||
on_error=on_error,
|
||||
@@ -30,4 +51,4 @@ def main():
|
||||
ws.run_forever()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
Reference in New Issue
Block a user