Esempio n. 1
0
 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'
Esempio n. 2
0
 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'
Esempio n. 3
0
 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'
Esempio n. 4
0
 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'
Esempio n. 5
0
    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
Esempio n. 6
0
 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!'})
Esempio n. 7
0
 def getMode():
         return prettyJson({
             'mode' : clk.mode
         })
Esempio n. 8
0
 def setPhase():
     return prettyJson(getDateTime())
Esempio n. 9
0
 def getWeather():
     return prettyJson(weather.report)
Esempio n. 10
0
 def getWeatherConfig():
     return prettyJson(weather.config)
Esempio n. 11
0
 def emit(self):
     self.sio.emit('osInfo', prettyJson(getReport()))
Esempio n. 12
0
 def onconnect_event():
     print('Client connected!')
     sio.emit('osInfo', prettyJson(getReport()))
Esempio n. 13
0
 def printConfig(self):
     print('Weather Station Config:')
     print(prettyJson(self.config))