Git Product home page Git Product logo

Comments (3)

Eng65745 avatar Eng65745 commented on July 18, 2024 1

Thanks for the quick answer. I'm a beginner with python, and was just playing around trying to find the esios api (there are quite a few, with different data) that better fits my small project (displaying in a HA dasboard a graph of prices from current time until end of day, or end of next day if after 20:30). Tinkering with the code from advanced developpers helps a lot, even if often I don't fully understand all the code.

Gracias!

from aiopvpc.

azogue avatar azogue commented on July 18, 2024

Hi @Eng65745,

To run an isolated piece of async code you need to invoke it with asyncio.run:

import asyncio
import aiohttp
from datetime import datetime
from aiopvpc import PVPCData

async def _show_current_pvpc_prices():
    async with aiohttp.ClientSession() as session:
        pvpc_handler = PVPCData(session=session, tariff="2.0TD")
        esios_data = await pvpc_handler.async_update_all(
            current_data=None, now=datetime.utcnow()
        )
    print(esios_data.sensors["PVPC"])

asyncio.run(_show_current_pvpc_prices())

In jupyter, the code-snippet from the README works without problems, as you can await coroutines in the cells.

For an invocation inside IDLE or as a python script, you'll need to call asyncio.run(coroutine()).

But the code-snippet is meant to just document how the library works, not to be used like that 😅

from aiopvpc.

azogue avatar azogue commented on July 18, 2024

To run an isolated piece of async code

For more context take a look here: https://realpython.com/async-io-python/

from aiopvpc.

Related Issues (20)

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.