Advertisement
hfreni

GetJSON.py

May 14th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import json
  2. import urllib2
  3. import math
  4.  
  5. METRES_PER_INCH = 0.0254
  6. LAUNCH_ANGLE = 44 #Optimal Launch Angle
  7. LAUNCH_HEIGHT = 13
  8. FIELD_SIZE = 140.5
  9. GOAL_X = 4.0941
  10. GOAL_Y = 139.9059
  11.  
  12. print '{'
  13. for y in range(0, 144):
  14.     x = 140.5 - y
  15.     data = json.load(urllib2.urlopen('http://vex.us.nallen.me/exec/extras/nbn_shooting?x=' + str(x*METRES_PER_INCH) + '&y=' + str(y*METRES_PER_INCH) + '&z='+ str(LAUNCH_HEIGHT * METRES_PER_INCH) +'&angle='+ str(LAUNCH_ANGLE)))
  16.     r = math.sqrt(math.pow(GOAL_X - x, 2) + math.pow(GOAL_Y - y, 2))
  17.     strPls = json.dumps(data, sort_keys=True,indent=4, separators=(',', ': '))
  18.     strD = strPls[:-1]
  19.  
  20.     if y == 144:
  21.         print '"position' + str(y) + '":' + strD + ', "length":' + str(r) + '},'
  22.     else:
  23.         print '"position' + str(y) + '":' + strD + ', "length":' + str(r) + '}'
  24. print '}'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement