def test_create_new(monkeypatch): test_user_name = 'test_user_name' test_address = 'test_address' class MockResponse: def __init__(self, data): self.data = data def json(self): return [self.data] def mock_post_success(*args, **kwargs): assert args[0] == 'http://test_address/api' assert kwargs['json'].get('devicetype') return MockResponse({ 'success': {'username': test_user_name} }) def mock_post_device_type_error(*args, **kwargs): return MockResponse({ 'error': {'type': 1} }) def mock_post_button_not_pressed(*args, **kwargs): return MockResponse({ 'error': {'type': 101} }) api = HueApi() monkeypatch.setattr(requests, 'post', mock_post_success) api.create_new_user(test_address) assert api.bridge_ip_address == test_address assert api.user_name == test_user_name assert api.base_url == 'http://test_address/api/test_user_name' monkeypatch.setattr(requests, 'post', mock_post_device_type_error) with pytest.raises(DevicetypeException): api.create_new_user(test_address) monkeypatch.setattr(requests, 'post', mock_post_button_not_pressed) with pytest.raises(ButtonNotPressedException): api.create_new_user(test_address)
from hue_api import HueApi import bs4 import urllib.request import time api = HueApi() # api.load_existing('Hue IP here') api.create_new_user('Hue IP here') api.fetch_lights() previous_price = 0 day_high = 0 api.turn_on() def get_price(): url = 'https://uk.finance.yahoo.com/quote/GME/chart?p=GME' \ '#eyJpbnRlcnZhbCI6MSwicGVyaW9kaWNpdHkiOjEsInRpbWVVbml0IjoibWludXRlIiwiY2FuZGxlV2lkdGgiOjguMTY1NDY3NjI1ODk5MjgsImZsaXBwZWQiOmZhbHNlLCJ2b2x1bWVVbmRlcmxheSI6dHJ1ZSwiYWRqIjp0cnVlLCJjcm9zc2hhaXIiOnRydWUsImNoYXJ0VHlwZSI6ImxpbmUiLCJleHRlbmRlZCI6ZmFsc2UsIm1hcmtldFNlc3Npb25zIjp7fSwiYWdncmVnYXRpb25UeXBlIjoib2hsYyIsImNoYXJ0U2NhbGUiOiJsaW5lYXIiLCJwYW5lbHMiOnsiY2hhcnQiOnsicGVyY2VudCI6MSwiZGlzcGxheSI6IkdNRSIsImNoYXJ0TmFtZSI6ImNoYXJ0IiwiaW5kZXgiOjAsInlBeGlzIjp7Im5hbWUiO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MCwiaWQiOiLigIxtYeKAjCAoNTAsQyxtYSwwKSIsImRpc3BsYXkiOiLigIxtYeKAjCAoNTAsQyxtYSwwKSJ9LCJvdXRwdXRzIjp7Ik1BIjoiI2FkNmVmZiJ9LCJwYW5lbCI6ImNoYXJ0IiwicGFyYW1ldGVycyI6eyJjaGFydE5hbWUiOiJjaGFydCJ9fX19 ' page = urllib.request.urlopen(url) soup = bs4.BeautifulSoup(page, "html.parser") price = soup.find('div', { 'class': 'My(6px) Pos(r) smartphone_Mt(6px)' }).find('span').text return float(price)
azure_key = r.json()["azure_key"] azure_end = r.json()["azure_end"] wit_key = r.json()["wit_key"] weather_key = r.json()["weather_key"] bridge_ip = r.json()["bridge_ip"] voice = r.json()["voice"] _config() #získání lokace pro počasí atd. g = geocoder.ip("me") #nastavení hue api = HueApi() try: api.create_new_user(bridge_ip) api.save_api_key(cache_file = "hue_token") except: api.load_existing(cache_file = "hue_token") api.fetch_lights() #inicializace regnozicačních objektů r = sr.Recognizer() m = sr.Microphone() #nastavení azure speech_config = speechsdk.SpeechConfig(endpoint=azure_end, subscription=azure_key) if(voice == "M"): speech_config.speech_synthesis_voice_name = "cs-CZ-AntoninNeural" else: