In [5]:
import json
from urllib.request import urlopen
from pylab import *
import dateutil
%matplotlib inline


raw_url = 'http://localhost:5000/counters/{}/data/'
deseasonalized_url = 'http://localhost:5000/counters/{}/data/deseasonalized/'

counters_url = 'http://localhost:5000/counters/'

counters = [x['properties']['id'] for x in json.loads(urlopen(counters_url).read().decode('utf8'))['features']]

In [13]:
def plot_counter(i):
    url = raw_url.format(str(i))
    data = json.loads(urlopen(url).read().decode('utf8'))
    dates = [dateutil.parser.parse(x['datetime']) for x in data['data']]
    
    inbound = [x['inbound'] for x in data['data']]
    plot(dates, inbound)
    
    outbound = [x['outbound'] for x in data['data']]
    plot(dates, outbound)
    
    url = deseasonalized_url.format(str(i))
    data = json.loads(urlopen(url).read().decode('utf8'))
    result = [x['result'] for x in data['data']]
    dates = [dateutil.parser.parse(x['datetime']) for x in data['data']]
    plot(dates,result)
    title(i)

    show()

In [14]:
plot_counter(9)



In [15]:
for i in counters:
    plot_counter(i)


---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-15-631d6539359b> in <module>()
      1 for i in counters:
----> 2     plot_counter(i)

<ipython-input-13-1d03905a8acb> in plot_counter(i)
     11 
     12     url = deseasonalized_url.format(str(i))
---> 13     data = json.loads(urlopen(url).read().decode('utf8'))
     14     result = [x['result'] for x in data['data']]
     15     dates = [dateutil.parser.parse(x['datetime']) for x in data['data']]

/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    159     else:
    160         opener = _opener
--> 161     return opener.open(url, data, timeout)
    162 
    163 def install_opener(opener):

/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py in open(self, fullurl, data, timeout)
    467         for processor in self.process_response.get(protocol, []):
    468             meth = getattr(processor, meth_name)
--> 469             response = meth(req, response)
    470 
    471         return response

/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py in http_response(self, request, response)
    577         if not (200 <= code < 300):
    578             response = self.parent.error(
--> 579                 'http', request, response, code, msg, hdrs)
    580 
    581         return response

/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py in error(self, proto, *args)
    505         if http_err:
    506             args = (dict, 'default', 'http_error_default') + orig_args
--> 507             return self._call_chain(*args)
    508 
    509 # XXX probably also want an abstract factory that knows when it makes

/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    439         for handler in handlers:
    440             func = getattr(handler, meth_name)
--> 441             result = func(*args)
    442             if result is not None:
    443                 return result

/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    585 class HTTPDefaultErrorHandler(BaseHandler):
    586     def http_error_default(self, req, fp, code, msg, hdrs):
--> 587         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    588 
    589 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 500: INTERNAL SERVER ERROR

In [ ]: