GithubHelp home page GithubHelp logo

py-citycom-mv-api's Introduction

citycom_mv_api

A python wrapper for citycom_mv api

Module Usage

import asyncio
import os

import aiohttp
from loguru import logger

from citycom_mv_api.citycom_mv_client import CityComMVClient
from citycom_mv_api.login import LoginError
from citycom_mv_api.models.exceptions import CitycomError

session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False), timeout=aiohttp.ClientTimeout(total=10))
try:
    # Example of usage
    client = CityComMVClient("[email protected]", "YYY", session)

    token_json_file = "token.json"
    if os.path.exists(token_json_file):
        await client.load_token_from_file(token_json_file)
    else:
        try:
            await client.login()
            await client.save_token_to_file(token_json_file)
        except LoginError as err:
            logger.error(f"Failed Login: (Code {err.code}): {err.error}")
            raise

    # refresh token example- currently not implemented, it just logins again
    token = client.get_token()
    await client.check_token()
    new_token = client.get_token()
    if token != new_token:
        print("Token refreshed")
        await client.save_token_to_file(token_json_file)

    print("access_token: " + token.access_token)

    customer = await client.get_customer()
    print(customer)

    reading = await client.get_last_meter_reading(customer.properties[0].meters[0].meter_id)
    print(reading)

except CitycomError as err:
    logger.error(f"Error: (Code {err.code}): {err.error}")
finally:
    await session.close()

py-citycom-mv-api's People

Contributors

shenharo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.