Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I set the API key in the script? #8

Open
Viss opened this issue Feb 22, 2020 · 2 comments
Open

How do I set the API key in the script? #8

Viss opened this issue Feb 22, 2020 · 2 comments

Comments

@Viss
Copy link

Viss commented Feb 22, 2020

I'd like to be able to set the API key in the script itself versus using environment variables, making it a bit more portable could you provide an example of how to do that?

@avryhof
Copy link
Owner

avryhof commented Feb 24, 2020

You can pass it in as a Keyword argument.

api = AmbientAPI(AMBIENT_API_KEY="your key here")

@kyrlon
Copy link

kyrlon commented Jun 16, 2024

I ended up using a json file to keep all of my values with the example below:

contents of AUTH.json:

{
    "AMBIENT_APPLICATION_KEY":"KEY_HEREEE",
    "AMBIENT_API_KEY":"KEY HERE",
    "AMBIENT_ENDPOINT":"https://rt.ambientweather.net/v1",
    "log_level": "debug"
}

ex.py script:

from ambient_api.ambientapi import AmbientAPI
import time, json
from pathlib import Path
import inspect

CURRENT_FILE_PATH = Path(inspect.getfile(lambda: None)).parent

LOG_FILE = CURRENT_FILE_PATH / "data.log"

with open(CURRENT_FILE_PATH / "AUTH.json") as fd:
    auth = json.load(fd)
    
api = AmbientAPI(**auth)

devices = api.get_devices()

device = devices[0]
time.sleep(1)
print(device.get_data())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants