Esempio n. 1
0
 def find_max(self, list):
     Firebase = kFirebase.Firebase()
     # print(list)
     for idx in range(len(list)):
         if list[idx] == max(list):
             # print('findmax',idx)
             Firebase.wa_update('mode/', {'auto_area': idx})
Esempio n. 2
0
    def _main(self):
        Firebase = kFirebase.Firebase()

        # Firebase.firebase_db()

        si = Firebase.load('info/si')
        # si = Firebase.load_si()
        # local = Firebase.load_local()
        local = Firebase.load('info/local')
        print(local)
        pageNo = 0

        for i in range(5):
            pageNo += 1

            url = self.mise_url(si, pageNo)
            print(url)
            response = requests.get(url)

            if (response.status_code == 200):
                # print('ok')
                data = response.json()
                for i in range(len(data['list'])):
                    tmp_data = data['list'][i]
                    if tmp_data['cityName'] == local:
                        # self.print_air_info(tmp_data)
                        dataList = self.air_info(tmp_data)
                        Firebase.update(dataList)
            else:
                print("Error code: " + response.status_code)
Esempio n. 3
0
    def worst_air(self):
        month, day, hour, min = self.date_time()

        Firebase = kFirebase.Firebase()
        # Firebase.firebase_db()
        area = ['kitchen', 'livingroom', 'room']

        pm10_list = []
        pm25_list = []

        for i in range(3):
            pm10path = 'inside/' + area[i] + '/' + str(month) + str(
                day) + '/' + str(hour) + ':' + str(min) + '/' + 'pm10Value'
            pm10value = Firebase.load(pm10path)
            pm10_list.append(pm10value)

            pm25path = 'inside/' + area[i] + '/' + str(month) + str(
                day) + '/' + str(hour) + ':' + str(min) + '/' + 'pm25Value'
            pm25value = Firebase.load(pm25path)
            pm25_list.append(pm25value)

        # worst: 3, bad: 2, normal: 1, good: 0
        auto_area = [0, 0, 0]

        print(pm10_list)
        print(pm25_list)

        for i in range(3):
            if pm10_list[i] >= 101 or pm25_list[i] >= 51:
                auto_area[i] = 3
            elif pm10_list[i] >= 151 or pm25_list[i] >= 26:
                auto_area[i] = 2
            elif pm10_list[i] >= 31 or pm25_list[i] >= 16:
                auto_area[i] = 1
            else:
                auto_area[i] = 0

        print(auto_area)

        pm10_array = np.array(pm10_list)
        pm25_array = np.array(pm25_list)

        if auto_area.count(1) > 1 or auto_area.count(2) > 1 or auto_area.count(
                3) > 1:
            self.find_max(pm25_array + pm10_array)
            return

        if sum(auto_area) == 0:
            print(1)
            Firebase.wa_update('mode/', {'auto_area': 1})
        else:
            self.find_max(auto_area)
Esempio n. 4
0
    def _main(self, second=1.0):
        # global end
        # if end:
        #     return

        Firebase = kFirebase.Firebase()
        Firebase.firebase_db()

        latitude = Firebase.load('outside/area/latitude')
        longitude = Firebase.load('outside/area/longitude')

        x, y = self.trans_coordinate(latitude, longitude)
        address, local, si = self.get_address('ko', latitude, longitude, "")
        print(address, local, si)

        Firebase.update({'now_location': address})
        # Firebase.update_address(address)
        Firebase.update({'local': local})
        # Firebase.update_local(local)
        Firebase.update({'si': si})
        # Firebase.update_si(si)
        # print(address)

        url = "http://newsky2.kma.go.kr/service/SecndSrtpdFrcstInfoService2/ForecastGrib?"
        ServiceKey = "ServiceKey="
        today = t.localtime()

        print(today)

        year = str(today.tm_year)
        day = ''
        mon = ''
        time = str(today.tm_hour)
        if today.tm_mon < 10:
            mon = "0" + str(today.tm_mon)
        else:
            mon = str(today.tm_mon)

        if today.tm_mday < 10:
            day = "0" + str(today.tm_mday)
        else:
            day = str(today.tm_mday)

        print(time)
        base_date = "&base_date=" + str(year) + str(mon) + str(day)
        if int(time) - 1 < 0:
            base_time = "&base_time=" + "23" + "45"
        else:
            if (int(time) - 1 < 10):
                base_time = "&base_time=" + '0' + str(int(time) - 1) + "45"
            else:
                base_time = "&base_time=" + str(int(time) - 1) + "45"
        nx = "&nx=" + str(x)
        ny = "&ny=" + str(y)
        url = url + ServiceKey + base_date + base_time + nx + ny + "&pageNo=1" + "&numOfRows=10&_type=json"

        print(url)

        response = requests.get(url)

        if response.status_code == 200:
            # print("ok")
            data = response.json()
            # print(data)
            tmp_data = data['response']['body']['items']['item']
            # print(tmp_data)

            temp = 0.0
            humid = 0.0

            if tmp_data[3]["category"] == "T1H":
                print('온도: ', tmp_data[3]['obsrValue'], '℃')
                temp = float(tmp_data[3]['obsrValue'])

            if tmp_data[1]["category"] == "REH":
                print('습도: ', tmp_data[1]['obsrValue'], '%')
                humid = float(tmp_data[1]['obsrValue'])

            Firebase.update({'temp': temp, 'humid': humid})
            # Firebase.update_temp(temp, humid)
            pass

        else:
            print("Error code: " + response.status_code)
Esempio n. 5
0
    def calc_hour(self):

        month, day, hour, min = self.date_time()
        print(month, day, hour, min)
        Firebase = kFirebase.Firebase()

        area = ['kitchen', 'livingroom', 'room']

        tmp_pm10 = []
        tmp_pm25 = []
        tmp_temp = []
        tmp_humid = []

        print('m', min)
        # d_min = 0

        for i in range(3):
            if min >= 55:
                d_min = 0
                while d_min < 56:
                    # print(100)
                    pm10path = 'inside/' + area[i] + '/' + str(month) + str(
                        day) + '/' + str(hour) + ':' + str(
                            d_min) + '/' + 'pm10Value'
                    pm10value = Firebase.load(pm10path)
                    # print(pm10value)
                    if pm10value is not None:
                        tmp_pm10.append(pm10value)

                    pm25path = 'inside/' + area[i] + '/' + str(month) + str(
                        day) + '/' + str(hour) + ':' + str(
                            d_min) + '/' + 'pm25Value'
                    pm25value = Firebase.load(pm25path)
                    if pm25value is not None:
                        tmp_pm25.append(pm25value)

                    temp_path = 'inside/' + area[i] + '/' + str(month) + str(
                        day) + '/' + str(hour) + ':' + str(
                            d_min) + '/' + 'temp'
                    temp_value = Firebase.load(temp_path)
                    if temp_value is not None:
                        tmp_temp.append(temp_value)
                    # print('temp',temp_value)

                    humid_path = 'inside/' + area[i] + '/' + str(month) + str(
                        day) + '/' + str(hour) + ':' + str(
                            d_min) + '/' + 'humid'
                    humid_value = Firebase.load(humid_path)
                    if humid_value is not None:
                        tmp_humid.append(humid_value)

                    d_min += 5

                print(tmp_temp)
                print(tmp_humid)
                print(tmp_pm10)
                print(tmp_pm25)

                print(area[i], month, day, hour)
                Firebase.wa_update(
                    'inside/' + area[i] + '/' + str(month) + str(day) +
                    '/ave/' + str(hour) + '/',
                    {'pm10Value': round(float(sum(tmp_pm10)) / 12, 2)})

                Firebase.wa_update(
                    'inside/' + area[i] + '/' + str(month) + str(day) +
                    '/ave/' + str(hour) + '/',
                    {'pm25Value': round(float(sum(tmp_pm25)) / 12, 2)})

                Firebase.wa_update(
                    'inside/' + area[i] + '/' + str(month) + str(day) +
                    '/ave/' + str(hour) + '/',
                    {'temp': round(float(sum(tmp_temp)) / 12, 2)})

                Firebase.wa_update(
                    'inside/' + area[i] + '/' + str(month) + str(day) +
                    '/ave/' + str(hour) + '/',
                    {'humid': round(float(sum(tmp_humid)) / 12, 2)})

        else:
            print(1)
            return
Esempio n. 6
0
    def calc_day(self):
        month, day, hour, min = self.date_time()

        Firebase = kFirebase.Firebase()
        # Firebase.firebase_db()

        area = ['kitchen', 'livingroom', 'room']

        d_hour = 0
        total_temp = []
        total_pm25 = []
        total_pm10 = []
        total_humid = []

        for i in range(len(area)):
            if hour == 23:
                while d_hour < 24:
                    pm10path = 'inside/' + area[i] + '/' + str(month) + str(
                        day) + '/ave/' + str(d_hour) + '/' + 'pm10Value'
                    pm10value = Firebase.load(pm10path)
                    # print(pm10value)
                    if pm10value is not None:
                        # print(pm10value)
                        total_pm10.append(pm10value)

                    pm25path = 'inside/' + area[i] + '/' + str(month) + str(
                        day) + '/ave/' + str(d_hour) + '/' + 'pm25Value'
                    pm25value = Firebase.load(pm25path)
                    if pm25value is not None:
                        # print(pm25value)
                        total_pm25.append(pm25value)

                    temp_path = 'inside/' + area[i] + '/' + str(month) + str(
                        day) + '/ave/' + str(d_hour) + '/' + 'temp'
                    temp_value = Firebase.load(temp_path)
                    if temp_value is not None:
                        total_temp.append(temp_value)
                        # print(temp_value)

                    humid_path = 'inside/' + area[i] + '/' + str(month) + str(
                        day) + '/ave/' + str(d_hour) + '/' + 'humid'
                    humid_value = Firebase.load(humid_path)
                    if humid_value is not None:
                        # print(humid_value)
                        total_humid.append(humid_value)

                    d_hour += 1

                Firebase.wa_update(
                    'inside/' + area[i] + '/' + str(month) + str(day) +
                    '/ave/day',
                    {'pm10Value': round(float(sum(total_pm10)) / 24, 2)})

                Firebase.wa_update(
                    'inside/' + area[i] + '/' + str(month) + str(day) +
                    '/ave/day',
                    {'pm25Value': round(float(sum(total_pm25)) / 24, 2)})

                Firebase.wa_update(
                    'inside/' + area[i] + '/' + str(month) + str(day) +
                    '/ave/day',
                    {'temp': round(float(sum(total_temp)) / 24, 2)})

                Firebase.wa_update(
                    'inside/' + area[i] + '/' + str(month) + str(day) +
                    '/ave/day',
                    {'humid': round(float(sum(total_humid)) / 24, 2)})
            else:
                print(2)
                return
Esempio n. 7
0
    def _main(self):
        Firebase = kFirebase.Firebase()
        # Firebase.firebase_db()

        self.calc_hour()
Esempio n. 8
0
import check_worst
# end = False


def _outside(second=1800.0):
    Weather = weather_api.WeatherAPI()
    Mise = openApi_call.MiseAPI()

    Weather._main()
    Mise._main()

    threading.Timer(second, _outside, [second]).start()


def _inside(second=3.0):
    Check_mise = worst_air.Check_mise()
    Check_worst = check_worst.Check_worst()

    # Check_mise._main()
    Check_worst._main()

    threading.Timer(second, _inside, [second]).start()


if __name__ == '__main__':
    Firebase = kFirebase.Firebase()
    Firebase.firebase_db()

    _outside()
    _inside()