Exemplo n.º 1
0
    def register_wakeup_time(self, origins, destinations, time, brekfast_time):
        global weather_and_traffic
        weather_and_traffic = get_weather_and_traffic()

        s = WakeupInfo("wakeup_info.json", origins, destinations, time, 0, brekfast_time)
        routing_info = self.get_routing_info(s.origins, s.destinations)
        print (routing_info)
        estimating_time = routing_info["rows"][0]["elements"][0]["duration"]["value"]
        s.estimating_time = timediff_to_humantime(estimating_time)
        status = s.save()
        if status == True:
            return "1"
        else:
            return "0"
Exemplo n.º 2
0
    def api(self):
        input_json = cherrypy.request.json
        print input_json
        try:
            s = WakeupInfo("wakeup_info.json", [], [], "", "", "")
            s.refresh()
            if "arrivalTime" in input_json.keys():
                s.time = input_json["arrivalTime"].encode("ascii", "ignore")
            if "breakfastTime" in input_json.keys():
                s.brekfast_time = input_json["breakfastTime"].encode("ascii", "ignore")

            s.save()
        except:
            print "API key time Error"
        else:
            print "Time updated! {0} and {1}".format(s.time, s.brekfast_time)

        if "alarmStatus" in input_json.keys():
            if input_json["alarmStatus"] == "silence":
                self.silence = True

        if "url" in input_json.keys():
            self.phone_url = input_json["url"]
            print "URL updated!"

        return "Hello. This is our API"
Exemplo n.º 3
0
    def is_wakeup_time(self):
        self.is_server_run = True
        # print("**********************************************************************************************************************************")
        s = WakeupInfo("wakeup_info.json", [], [], "", "", "")
        status = s.refresh()

        global weather_and_traffic

        time_now_unix = time.mktime((dt.datetime.now()).timetuple())
        wakeup_time_unix = getWakeupTimeInUnix(s.time)

        estimating_time_unix = (
            get_sec(s.estimating_time) + get_sec(s.estimating_time) * weather_and_traffic["traffic_level"] / 10.0
        )

        remaining_time = abs(wakeup_time_unix - time_now_unix)

        must_wakeup_time = wakeup_time_unix - estimating_time_unix - get_sec(s.brekfast_time)

        # if abs( remaining_time - estimating_time_unix ) < 60:
        # if abs( remaining_time - estimating_time_unix ) - self.diff > 82000:
        # if abs( remaining_time - estimating_time_unix ) - self.diff > 82000:
        if must_wakeup_time - time_now_unix < 0 and self.diff >= 0:
            decision = True
        else:
            decision = False

        if self.diff >= 0:
            # est_time = abs( remaining_time - estimating_time_unix )
            est_time = abs(remaining_time - estimating_time_unix - get_sec(s.brekfast_time))
        else:
            # est_time = 86400 + remaining_time - estimating_time_unix
            est_time = 86400 + remaining_time - estimating_time_unix - get_sec(s.brekfast_time)

        answer_template = """
        <tbody>
        <alarm>
        {0}
        </alarm>
        <string1>
        {1}
        </string1>
        <string2>
        {2}
        </string2>
        </tbody>

        """
        global string1, string2

        string1 = "{0}".format(str(timediff_to_humantime(est_time)))
        string2 = "Jam: {0}, Tem: {1}".format(weather_and_traffic["traffic_level"], weather_and_traffic["fact_temp"])

        # print( "Weather and traffic info:          ", weather_and_traffic )
        # print( "Estimating time (from google):     ", timediff_to_humantime( get_sec( s.estimating_time ) ) )
        # print( "Estimating time (add from yandex): ", timediff_to_humantime( get_sec( s.estimating_time ) * weather_and_traffic["traffic_level"] / 10.0 ) )
        # print( "Estimating time (final):           ", timediff_to_humantime( estimating_time_unix ), estimating_time_unix )
        print ("Remaining time:                    ", timediff_to_humantime(est_time), est_time)
        print ("Decision:                          ", decision)
        # print( "diff:                              ", timediff_to_humantime( self.diff ), self.diff )
        # print( "remaining_time:                    ", timediff_to_humantime( remaining_time ), remaining_time )

        print ("**********************************************************************************")

        # self.diff = abs( remaining_time - estimating_time_unix )
        self.diff = must_wakeup_time - time_now_unix
        return decision