Advertisement
LargeGeek

Dual Attack OBS Import

Jan 17th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. # This is a little Python script to be using in conjunction with the 'Dual Attack' score clock app.
  2. # It will generate separate files for each piece of data that the app tracks.
  3. # You can point text sources to these files in Open Broadcast Software to track game state on an overlay.
  4. # I am by no means an expert on any of this, so do what you will with it.
  5. # It seems to work well enough for me, with a momentary blanking on OBS when there are write/read collision.
  6.  
  7. import urllib.request
  8. import urllib.error
  9. import json
  10. from time import sleep
  11.  
  12.  
  13. svrIP = input('Enter Server IP: ') # Ask user to input server IP
  14. server = "http://"+svrIP+":8080/data" # Build full address
  15. print('Currently generating Dual Attack files...\nCTRL+C to quit') # Print instructions
  16.  
  17. # Main function to do all the work
  18. def file_gen():
  19.     with urllib.request.urlopen(server) as url: # Look at server and dump json into jdata
  20.         jdata = json.loads(url.read().decode())
  21.        
  22.         #Build individual variables for each json object
  23.         jTurn = jdata["score"]["turn"]
  24.         jTime1 = jdata["timer1"]
  25.         jTime2 = jdata["timer2"]
  26.         jCp1 = jdata["score"]["cp1"]
  27.         jCp2 = jdata["score"]["cp2"]
  28.        
  29.         #Write data to each file
  30.         wTurn = open("turn.txt","w+")
  31.         wTurn.write(jTurn)
  32.        
  33.         wTime1 = open("time1.txt","w+")
  34.         wTime1.write(jTime1)
  35.        
  36.         wTime2 = open("time2.txt","w+")
  37.         wTime2.write(jTime2)
  38.        
  39.         wCp1 = open("CP1.txt","w+")
  40.         wCp1.write(str(jCp1))
  41.        
  42.         wCp2 = open("CP2.txt","w+")
  43.         wCp2.write(str(jCp2))
  44.  
  45. #Loop to run function or exit        
  46. try:
  47.     while True:
  48.         file_gen()
  49.         sleep(0.5) # adds a delay so you are writing and polling needlessly
  50. except KeyboardInterrupt:
  51.     quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement