Coder Social home page Coder Social logo

go-datadis's Introduction

Datadis Go Client

โš ๏ธ Work in progress, experimental

Go API to read Datadis energy consumption info.

You'll need https://www.datadis.es account to use this package.

Example

package main

import (
        "fmt"
        "os"
        "time"

        "github.com/rubiojr/go-datadis"
)

// Fetch datadis last day consumption
func main() {
        client := datadis.NewClient()
        client.Login(os.Getenv("DATADIS_USERNAME"), os.Getenv("DATADIS_PASSWORD"))
        s, err := client.Supplies()
        if err != nil {
                panic(err)
        }

        now := time.Now()
        year, month, day := now.Date()
        // Read yesterday's data
        date := time.Date(year, month, day-1, 0, 0, 0, 0, now.UTC().Location())
        data, err := client.ConsumptionData(&s[0], date, date)
        for _, d := range data {
                fmt.Println("CUPS: ", d.Cups)
                fmt.Println("Date: ", d.Date)
                fmt.Println("Time: ", d.Time)
                fmt.Printf("Consumption: %f KWh\n", d.Consumption)
                fmt.Println("Obtained Method: ", d.ObtainMethod)
        }
}

Building the command line client

make

Using the sample client

Export the datadis username and password as environment variables:

export DATADIS_USERNAME="username here"
export DATADIS_PASSWORD="password here"

Run the client without arguments:

./bin/datadis

Related

go-datadis's People

Contributors

rubiojr avatar

Watchers

 avatar  avatar  avatar

Forkers

kyosfonica

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.