Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is a little Python script to be using in conjunction with the 'Dual Attack' score clock app.
- # It will generate separate files for each piece of data that the app tracks.
- # You can point text sources to these files in Open Broadcast Software to track game state on an overlay.
- # I am by no means an expert on any of this, so do what you will with it.
- # It seems to work well enough for me, with a momentary blanking on OBS when there are write/read collision.
- import urllib.request
- import urllib.error
- import json
- from time import sleep
- svrIP = input('Enter Server IP: ') # Ask user to input server IP
- server = "http://"+svrIP+":8080/data" # Build full address
- print('Currently generating Dual Attack files...\nCTRL+C to quit') # Print instructions
- # Main function to do all the work
- def file_gen():
- with urllib.request.urlopen(server) as url: # Look at server and dump json into jdata
- jdata = json.loads(url.read().decode())
- #Build individual variables for each json object
- jTurn = jdata["score"]["turn"]
- jTime1 = jdata["timer1"]
- jTime2 = jdata["timer2"]
- jCp1 = jdata["score"]["cp1"]
- jCp2 = jdata["score"]["cp2"]
- #Write data to each file
- wTurn = open("turn.txt","w+")
- wTurn.write(jTurn)
- wTime1 = open("time1.txt","w+")
- wTime1.write(jTime1)
- wTime2 = open("time2.txt","w+")
- wTime2.write(jTime2)
- wCp1 = open("CP1.txt","w+")
- wCp1.write(str(jCp1))
- wCp2 = open("CP2.txt","w+")
- wCp2.write(str(jCp2))
- #Loop to run function or exit
- try:
- while True:
- file_gen()
- sleep(0.5) # adds a delay so you are writing and polling needlessly
- except KeyboardInterrupt:
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement