def getStatus(): try: type = flask_request.args.get('type') if (type == 'hh'): return prettyJson(clk.hh.getStatus()) if (type == 'mm'): return prettyJson(clk.mm.getStatus()) return 'Invalid type' except Exception as e: print(e) return 'Invalid parameters'
def setMode(): try: mode = flask_request.args.get('mode') clk.mode = mode return prettyJson({ 'mode' : clk.mode }) except Exception as e: print(e) return 'Invalid parameters'
def setWeatherConfig(): try: # Get arguments for parameter in flask_request.args: value = flask_request.args.get(parameter) # Update parameter weather.updateParam(parameter, value) weather.printConfig() weather.updateWeatherReport() return prettyJson(weather.config) except Exception as e: print(e) return 'Invalid parameters'
def setParameter(): try: type = flask_request.args.get('type') parameter = flask_request.args.get('parameter') value = int(flask_request.args.get('value')) if (type == 'hh'): clk.hh.setParameter(parameter, value) elif (type == 'mm'): clk.mm.setParameter(parameter, value) else: return 'Invalid type' return prettyJson({'status': 'ok'}) except Exception as e: print(e) return 'Invalid parameters'
def updateWeatherReport(self): url = 'https://api.openweathermap.org/data/2.5/onecall?' url = url + 'lat=' + self.config['latitude'] + '&' url = url + 'lon=' + self.config['longitude'] + '&' url = url + 'exclude=minutely&' url = url + 'units=metric&' url = url + 'lang=es&' url = url + 'appid=' + self.config['openWeatherApi'] with request.urlopen(url) as con: self.report = json.loads(con.read().decode()) print('Weather Station Report Update:') print(prettyJson( { 'location' : self.config['location'], 'temperature' : str(self.report['current']['temp']) + 'C', 'pressure' : str(self.report['current']['pressure']) + 'mbar', 'humidity' : str(self.report['current']['humidity']) + '%', 'weather' : self.report['current']['weather'][0]['description'] } )) return self.report
def setTimezone(): content = flask_request.get_json(silent=True) if (content != None): setTimeZone(content['nameValue']) clk.timezone = pytz.timezone(content['nameValue']) return prettyJson({'status' : 'Timezone modified!'})
def getMode(): return prettyJson({ 'mode' : clk.mode })
def setPhase(): return prettyJson(getDateTime())
def getWeather(): return prettyJson(weather.report)
def getWeatherConfig(): return prettyJson(weather.config)
def emit(self): self.sio.emit('osInfo', prettyJson(getReport()))
def onconnect_event(): print('Client connected!') sio.emit('osInfo', prettyJson(getReport()))
def printConfig(self): print('Weather Station Config:') print(prettyJson(self.config))