In [1]:
import os
import json
import time
import requests
from IPython.display import Latex, display

In [2]:
with open(os.path.abspath('../bin/config.json')) as f:
    cfg = json.load(f)


---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-2-a6671989acf2> in <module>()
----> 1 with open(os.path.abspath('../bin/config.json')) as f:
      2     cfg = json.load(f)

IOError: [Errno 2] No such file or directory: '/home/dcouture/git/mathyourlife/TSatPy/defense/bin/config.json'

In [3]:
BASE_URI = 'http://localhost:8083'
def print_state():
    r = requests.get('%s/plant/state' % BASE_URI)
    state = r.json()
    return display(Latex(r'\begin{equation}q=%s, \omega=%s\end{equation}' % (state['q'], state['w'])))

In [4]:
end_time = time.time() + 10
while time.time() < end_time:
    print_state()
    time.sleep(1)


---------------------------------------------------------------------------
ConnectionError                           Traceback (most recent call last)
<ipython-input-4-b462b6cdf841> in <module>()
      1 end_time = time.time() + 10
      2 while time.time() < end_time:
----> 3     print_state()
      4     time.sleep(1)

<ipython-input-3-193afa1e32ac> in print_state()
      1 BASE_URI = 'http://localhost:8083'
      2 def print_state():
----> 3     r = requests.get('%s/plant/state' % BASE_URI)
      4     state = r.json()
      5     return display(Latex(r'\begin{equation}q=%s, \omega=%s\end{equation}' % (state['q'], state['w'])))

/home/dcouture/.virtualenvs/tsat/local/lib/python2.7/site-packages/requests/api.pyc in get(url, **kwargs)
     53 
     54     kwargs.setdefault('allow_redirects', True)
---> 55     return request('get', url, **kwargs)
     56 
     57 

/home/dcouture/.virtualenvs/tsat/local/lib/python2.7/site-packages/requests/api.pyc in request(method, url, **kwargs)
     42 
     43     session = sessions.Session()
---> 44     return session.request(method=method, url=url, **kwargs)
     45 
     46 

/home/dcouture/.virtualenvs/tsat/local/lib/python2.7/site-packages/requests/sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert)
    381             'allow_redirects': allow_redirects,
    382         }
--> 383         resp = self.send(prep, **send_kwargs)
    384 
    385         return resp

/home/dcouture/.virtualenvs/tsat/local/lib/python2.7/site-packages/requests/sessions.pyc in send(self, request, **kwargs)
    484         start = datetime.utcnow()
    485         # Send the request
--> 486         r = adapter.send(request, **kwargs)
    487         # Total elapsed time of the request (approximately)
    488         r.elapsed = datetime.utcnow() - start

/home/dcouture/.virtualenvs/tsat/local/lib/python2.7/site-packages/requests/adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
    376 
    377         except MaxRetryError as e:
--> 378             raise ConnectionError(e)
    379 
    380         except _ProxyError as e:

ConnectionError: HTTPConnectionPool(host='localhost', port=8083): Max retries exceeded with url: /plant/state (Caused by <class 'socket.error'>: [Errno 111] Connection refused)

In [9]:
import sys
import os
import json

In [10]:
with open(os.path.abspath('bin/config.json')) as f:
    print json.load(f)


{u'api_port': 8083, u'log_file': u'/tmp/tsatpy.log', u'api_host': u'localhost'}

In [ ]: