Skip to main content

Asyncio library for the Automatic API

Project description

https://img.shields.io/pypi/v/aioautomatic.svg https://img.shields.io/travis/armills/aioautomatic.svg https://img.shields.io/coveralls/armills/aioautomatic.svg

Asyncio library for the Automatic API

  • Free software: Apache Software License 2.0

All methods are python wrappers of the API definitions defined by Automatic.

Usage

It is recommended to manage the aiohttp ClientSession object externally and pass it to the Client constructor. (See the aiohttp documentation.) If not passed to Server, a ClientSession object will be created automatically.

Query for information from the users account.

import asyncio
import aioautomatic
import aiohttp
from datetime import datetime
from datetime import timedelta

@asyncio.coroutine
def loop():
    aiohttp_session = aiohttp.ClientSession()
    try:
        client = aioautomatic.Client(
            '<client_id>',
            '<secret>',
            aiohttp_session)
        session = yield from client.create_session_from_password(
                '<user_email>', '<user_password>')

        # Fetch a list of vehicles associated with the user account
        vehicles = yield from session.get_vehicles()
        print(vehicles)
        print(vehicles[0].make)
        print(vehicles[0].model)
        print(vehicles[0].fuel_level_percent)

        # Fetch a list of all trips in the last 10 days
        min_end_time = datetime.utcnow() - timedelta(days=10)
        trips = yield from session.get_trips(ended_at__gte=min_end_time, limit=10)
        print(trips)
        print(trips[0].start_location.lat)
        print(trips[0].start_location.lon)
        print(trips[0].start_address.name)
        print(trips[0].distance_m)
        print(trips[0].duration_s)

        # If more than 10 trips exist, get the next page of results
        if trips.next is not None:
            trips = yield from trips.get_next()
            print(trips)

    finally:
        yield from aiohttp_session.close()

asyncio.get_event_loop().run_until_complete(loop())

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aioautomatic-0.1.1.tar.gz (13.9 kB view details)

Uploaded Source

File details

Details for the file aioautomatic-0.1.1.tar.gz.

File metadata

  • Download URL: aioautomatic-0.1.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aioautomatic-0.1.1.tar.gz
Algorithm Hash digest
SHA256 500778c9ca159008016b36240d9f987bfa137f080abaa91849181b258a05a57d
MD5 c326c5fab1746720df88c082b4d3cda8
BLAKE2b-256 3638b40c023fb49ae3a934765ebd6944745c138bb1de2e1f0251ca4139211d11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page