""" color tests with names and codes """ from aqi import Aqi my_aqi = Aqi() for code1 in my_aqi.all_color_codes(): for code2 in my_aqi.all_color_codes(): print("0x%08X 0x%08X" % (code1, code2))
def handle_message(event): global data_time global data_index global air_data global user_data global user_data_filename if not (event.source.user_id in user_data): user_data[event.source.user_id] = { "subscribe_site": [], "aqi_format": "simple" } #rewrite_user_data(user_data_filename,user_data) #write the data in storage if datetime.datetime.now( ) - delta > data_time or data_time.hour != datetime.datetime.now( ).hour: air_data = get_data() data_index = get_data_index(air_data) data_time = datetime.datetime.now() input_text = event.message.text input_texts = input_text.split(' ') out_text = "" try: if input_texts[0] == "add": if input_texts[1] in data_index: if not (input_texts[1] in user_data[event.source.user_id] ["subscribe_site"]): user_data[ event.source.user_id]["subscribe_site"].append( input_texts[1]) #rewrite_user_data(user_data_filename,user_data) #write the data in storage out_text = "add success" else: out_text = "site already exist" else: out_text = "add fail, name error" elif input_texts[0] == "delete": if input_texts[1] in user_data[ event.source.user_id]["subscribe_site"]: user_data[event.source.user_id]["subscribe_site"].remove( input_texts[1]) #rewrite_user_data(user_data_filename,user_data) #write the data in storage out_text = "remove " + input_texts[1] + " from subscribe" else: out_text = "delete fail, site doesn't exist" elif input_texts[0] == "get": out_text = "" if user_data[event.source.user_id]["aqi_format"] == "simple": for i in user_data[event.source.user_id]["subscribe_site"]: #result = json.dumps(air_data[data_index[i]], ensure_ascii=False) out_text = out_text + Aqi.aqi_with_simple_format( air_data[data_index[i]]) elif user_data[ event.source.user_id]["aqi_format"] == "complex": for i in user_data[event.source.user_id]["subscribe_site"]: #result = json.dumps(air_data[data_index[i]], ensure_ascii=False) out_text = out_text + Aqi.aqi_with_complex_format( air_data[data_index[i]]) else: out_text = "format error" if out_text == "": out_text = "subscribe is empty" elif input_texts[0] == "list": out_text = "aqi format : " + str(user_data[ event.source.user_id]["aqi_format"]) + "\nsubscribed : " for i in user_data[event.source.user_id]["subscribe_site"]: out_text = out_text + str(i) + "," out_text = out_text + "\nall site:" for i in data_index.keys(): out_text = out_text + str(i) + "," elif input_texts[0] == "help": out_text = "Usage:\n <command> [options]\nCommands:\n add \n delete\n list\n get\n help\n set format\n" elif input_texts[0] == "who": out_text = event.source.user_id elif input_texts[0] == "alluser": #u=get_user_data(user_data_filename) out_text = json.dumps(user_data, ensure_ascii=False) elif input_texts[0] == "set": if input_texts[1] == "format": if input_texts[2] == "simple": user_data[ event.source.user_id]["aqi_format"] = "simple" out_text = "set format to simple" #rewrite_user_data(user_data_filename,user_data) #write the data in storage elif input_texts[2] == "complex": user_data[ event.source.user_id]["aqi_format"] = "complex" out_text = "set format to complex" #rewrite_user_data(user_data_filename,user_data) #write the data in storage else: out_text = "input error" else: out_text = "input error" elif input_texts[0] == "fsm": message = ImageSendMessage("https://i.imgur.com/3YGE57U.png", "https://i.imgur.com/08uqJTl.png") line_bot_api.reply_message(event.reply_token, message) return else: out_text = "command not found" except IndexError: out_text = "input error" message = TextSendMessage(out_text) line_bot_api.reply_message(event.reply_token, message)
""" unit test for Aqi class """ from aqi import Aqi print("Starting...") my_aqi = Aqi() for adjust in ("None", "LRAPA", "AQ+U"): for size in ("2.5", "10.0"): print("Adjust: %s Size: %s" % (adjust, size)) for raw in range(0, 501, 5): aqi_value = my_aqi.sensor_to_aqi(raw, adjust, size) print ("Category: %s Raw: %d Adjusted: %d AQI: %d" % \ (my_aqi.category, raw, my_aqi.adjusted_value, aqi_value))
# pylint: disable=unused-import import time import board import busio from digitalio import DigitalInOut, Direction, Pull import adafruit_pm25 import displayio from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font from adafruit_display_shapes.rect import Rect from adafruit_display_shapes.circle import Circle from aqi import Aqi my_aqi = Aqi() # initialize Aqi class reset_pin = None # If you have a GPIO, its not a bad idea to connect it to the RESET pin # reset_pin = DigitalInOut(board.G0) # reset_pin.direction = Direction.OUTPUT # reset_pin.value = False # arial12 = bitmap_font.load_font("/fonts/Arial-12.bdf") arial16 = bitmap_font.load_font("/fonts/Arial-16.bdf") # arial24 = bitmap_font.load_font("/fonts/Arial-Bold-24.bdf") display = board.DISPLAY group = displayio.Group(max_size=25) MAXWIDTH = 120
# pylint: disable=unused-import import time import board import busio from digitalio import DigitalInOut, Direction, Pull import adafruit_pm25 import displayio from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font from adafruit_display_shapes.rect import Rect from adafruit_display_shapes.circle import Circle from aqi import Aqi my_aqi = Aqi() # initialize Aqi class reset_pin = None # If you have a GPIO, its not a bad idea to connect it to the RESET pin # reset_pin = DigitalInOut(board.G0) # reset_pin.direction = Direction.OUTPUT # reset_pin.value = False # arial12 = bitmap_font.load_font("/fonts/Arial-12.bdf") arial16 = bitmap_font.load_font("/fonts/Arial-16.bdf") # arial24 = bitmap_font.load_font("/fonts/Arial-Bold-24.bdf") display = board.DISPLAY group = displayio.Group(max_size=25) outer_circle = Circle(120, 120, 119, outline=0xFFFFFF, stroke=30)
# pylint: disable=unused-import import time import board import busio from digitalio import DigitalInOut, Direction, Pull import adafruit_pm25 import displayio from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font from adafruit_display_shapes.rect import Rect from adafruit_display_shapes.circle import Circle from aqi import Aqi my_aqi = Aqi() # initialize Aqi class reset_pin = None # If you have a GPIO, its not a bad idea to connect it to the RESET pin # reset_pin = DigitalInOut(board.G0) # reset_pin.direction = Direction.OUTPUT # reset_pin.value = False # arial12 = bitmap_font.load_font("/fonts/Arial-12.bdf") arial16 = bitmap_font.load_font("/fonts/Arial-16.bdf") # arial24 = bitmap_font.load_font("/fonts/Arial-Bold-24.bdf") display = board.DISPLAY group = displayio.Group(max_size=25) outer_circle = Circle(120, 120, 119, outline=0xFFFFFF, stroke=60)