def temperatures(request): if not settings.LIST_THERMOMETERS_API is None: ret = requests.get("%stemperatures=True" % settings.LIST_THERMOMETERS_API) therms = ret.json() else: therms = read_temperatures() known_therms = {} for x in Thermometer.objects.all(): known_therms[x.tid] = [x.caption, x.is_internal_reference, x.is_external_reference] out = {} for tid, data in therms.items(): try: out[known_therms[tid][0]] = { "temp": data, "is_internal": known_therms[tid][1], "is_external": known_therms[tid][2]} except KeyError: out[tid] = [data, False] response = HttpResponse( content=simplejson.dumps(out), content_type="application/json") response['Cache-Control'] = 'no-cache' return response
def read(self,): return read_temperatures(self.tid)[self.tid]["celsius"]