예제 #1
0
def setup_nest():
    #
    name = raw_input("Enter the name: ")
    #
    try:
        #
        print('The web browser will open to the Nest website.')
        print(
            'Please sign in and grant permissions for the HomeControl-server to interact with the Nest account.'
        )
        sleep(5)
        #
        client_id = get_binding_detail('nest_account', 'client_id')
        client_secret = get_binding_detail('nest_account', 'client_secret')
        state = 'STATE'
        #
        url_auth = 'https://home.nest.com/login/oauth2?client_id={client_id}&state={state}'.format(
            client_id=client_id, state=state)
        webbrowser.open(url_auth, new=1)
        #
        pincode = raw_input("Enter pincode: ")
        #
        token_response = get_accesstoken(client_id, client_secret, pincode)
        #
        ################################
        #
    except:
        print("\n!! An error has ocurred - please try again !!")
        print(
            "\n****************************************************************\n"
        )
        return
    #
    new_acc = {}
    new_acc['type'] = 'nest_account'
    new_acc['name'] = name
    new_acc['details_private'] = {
        'tokenexpiry': token_response['tokenexpiry'],
        'token': token_response['token'],
        'state': state,
        'redirect_url': ''
    }
    new_acc['details_public'] = {}
    #
    return new_acc
예제 #2
0
def getRegions_list():
    url = '{url}{uri}?key={key}'.format(
        url=BASE_URL,
        uri=URI_LIST_REGION.format(datatype='json'),
        key=get_binding_detail('metoffice', 'app_key'))
    r = requests.get(url)
    #
    if r.status_code == requests.codes.ok:
        locations = r.json()
        return locations['Locations']['Location']
    else:
        return False
예제 #3
0
def getForcast(frequency):
    # frequency = '3hourly' or 'daily'
    url = '{url}{uri}?res={frequency}&key={key}'.format(
        url=BASE_URL,
        uri=URI_FORECAST_SITE.format(datatype='json', locationId=LOCATION_id),
        frequency=frequency,
        key=get_binding_detail('metoffice', 'app_key'))
    r = requests.get(url)
    #
    if r.status_code == requests.codes.ok:
        return r.json()
    else:
        return False
def get_articles(source='', sortby=''):
    #
    if source == '':
        raise Exception
    if sortby not in LIST_SORTBY:
        raise Exception
    #
    query = QUERY_ARTICLES_APIKEY.format(api_key=get_binding_detail('newsapi', 'app_key'))
    query += '&' + QUERY_ARTICLES_SOURCE.format(source=source)
    if not sortby=='':
        query += '&' + QUERY_ARTICLES_SORTBY.format(sortby=sortby)
    #
    url = '{url}{uri}?{query}'.format(url=BASE_URL,
                                      uri=URI_ARTICLES,
                                      query=query)
    #
    r = requests.get(url)
    #
    if r.status_code == requests.codes.ok:
        return r.json()
    else:
        return {'status': 'ERROR'}
예제 #5
0
 def _clientsecret(self):
     return get_binding_detail(self._type, 'client_secret')
예제 #6
0
 def _clientid(self):
     return get_binding_detail(self._type, 'client_id')
예제 #7
0
 def _port(self):
     return get_binding_detail(self._type, 'port')