def send_data(): """Send data to the website with openweather data.""" try: token = get_token() req = setup_request() while True: data = get_data() if data: header = {"Authorization": f"Token {token}"} temp = data.get("temp") timestamp = utcisoformat(datetime.now()) print(f"Sending data {temp} at {timestamp}") data = { "sensor_type": "T", "device": "Raspberry", "measure": temp, "timestamp": timestamp, "name": "BMP280", } response = req.post("http://www.simteiva.fr/api/v1/", headers=header, data=data) time.sleep(10) except KeyboardInterrupt: logger.warning("Interrupted script execution with keyboard") sys.exit()
def text_reply(msg): text = msg.text if text.find('电影') > -1: return '好看的电影呢' elif text.find('傻') > -1: return '你很聪明么?' elif text.find('天气') > -1: return weather.get_data('北京') elif text.find('在吗') > -1: return say_notice() return msg.text
def test_local(self): result = get_data("22031") # Fairfax assert (("Sunny" in result["weather"]) or ("Fair" in result["weather"]) or ("Windy" in result["weather"]) or ("Rainy" in result["weather"]) or ("Snowy" in result["weather"]) or ("Cloudy" in result["weather"]))
def test_westcoast(self): result = get_mood(get_data("90001")) # Los Angeles assert result["mood"] in mood_types
def test_midwest(self): result = get_mood(get_data("60007")) # Chicago assert result["mood"] in mood_types
def test_local(self): result = get_mood(get_data("22031")) # Fairfax assert result["mood"] in mood_types
def test_westcoast(self): result = get_data("90001") # Los Angeles assert (("Sunny" in result["weather"]) or ("Fair" in result["weather"]) or ("Windy" in result["weather"]) or ("Rainy" in result["weather"]) or ("Snowy" in result["weather"]) or ("Cloudy" in result["weather"]))
def test_midwest(self): result = get_data("60007") # Chicago assert (("Sunny" in result["weather"]) or ("Fair" in result["weather"]) or ("Windy" in result["weather"]) or ("Rainy" in result["weather"]) or ("Snowy" in result["weather"]) or ("Cloudy" in result["weather"]))