Exemplo n.º 1
0
def main():
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

    try:
        logging.info("logging in as %s...", USERNAME)
        token = linky.login(USERNAME, PASSWORD)
        logging.info("logged in successfully!")

        logging.info("retrieving data...")
        today = datetime.date.today()
        
        # Years
        res_year = linky.get_data_per_year(token)

        # 12 months ago - today
        res_month = linky.get_data_per_month(token, dtostr(today - relativedelta(months=11)), \
                                             dtostr(today))


        # One month ago - yesterday
        res_day = linky.get_data_per_day(token, dtostr(today - relativedelta(days=1, months=1)), \
                                         dtostr(today - relativedelta(days=1)))


        # Yesterday and the day before
        res_hour = linky.get_data_per_hour(token, dtostr(today - relativedelta(days=2)), \
                                           dtostr(today))
        

        logging.info("got data!")
############################################
		# Export of the JSON files, with exception handling as Enedis website is not robust and return empty data often
        try:
            export_hours_values(res_hour)
        except Exception as exc:
        	# logging.info("hours values non exported")
            logging.error(exc)

        try:
            export_days_values(res_day)
        except Exception:
            logging.info("days values non exported")
            sys.exit(70)

        try:
            export_months_values(res_month)
        except Exception:
            logging.info("months values non exported")

        try:
            export_years_values(res_year)
        except Exception:
        	logging.info("years values non exported")

############################################
 
    except linky.LinkyLoginException as exc:
        logging.error(exc)
        sys.exit(1)
Exemplo n.º 2
0
def main():
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

    try:
        logging.info("logging in as %s...", USERNAME)
        token = linky.login(USERNAME, PASSWORD)
        logging.info("logged in successfully!")

        logging.info("retrieving data...")
        today = datetime.date.today()

        # Years
        res_year = linky.get_data_per_year(token)

        # 12 months ago - today
        res_month = linky.get_data_per_month(token, dtostr(today - relativedelta(months=11)),
                                             dtostr(today))

        # One month ago - yesterday
        res_day = linky.get_data_per_day(token, dtostr(today - relativedelta(days=1, months=1)),
                                         dtostr(today - relativedelta(days=1)))


        # Yesterday and the day before
        res_hour = linky.get_data_per_hour(token, dtostr(today - relativedelta(days=2)), \
                                           dtostr(today))
        

        logging.info("got data!")
        ############################################
        # Export of the JSON files, with exception handling as Enedis website is not robust and return empty data often
        try:
            export_hours_values(res_hour)
        except Exception as exc:
            # logging.info("hours values non exported")
            logging.error(exc)

        try:
            export_days_values(res_day)
        except Exception:
            logging.info("days values non exported")
            sys.exit(70)

        try:
            export_months_values(res_month)
        except Exception:
            logging.info("months values non exported")

        try:
            export_years_values(res_year)
        except Exception:
            logging.info("years values non exported")

        ############################################

    except linky.LinkyLoginException as exc:
        logging.error(exc)
        sys.exit(1)
Exemplo n.º 3
0
def main():
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-o",
        "--output-dir",
        type=str,
        default="out",
        help="the directory in which the graphs will be placed")
    args = parser.parse_args()
    outdir = args.output_dir

    try:
        locale.setlocale(locale.LC_ALL, 'fr_FR.utf8')
    except locale.Error as exc:
        logging.error(exc)

    try:
        logging.info("logging in as %s...", USERNAME)
        token = linky.login(USERNAME, PASSWORD)
        logging.info("logged in successfully!")

        logging.info("retreiving data...")
        today = datetime.date.today()
        res_year = linky.get_data_per_year(token)

        # 6 months ago - today
        res_month = linky.get_data_per_month(
            token, dtostr(today - relativedelta(months=6)), dtostr(today))

        # One month ago - yesterday
        res_day = linky.get_data_per_day(
            token, dtostr(today - relativedelta(days=1, months=1)),
            dtostr(today - relativedelta(days=1)))

        # Yesterday - today
        res_hour = linky.get_data_per_hour(
            token, dtostr(today - relativedelta(days=1)), dtostr(today))

        logging.info("got data!")
        logging.info("generating graphs...")

        generate_graph_months(outdir, res_month)
        generate_graph_years(outdir, res_year)
        generate_graph_days(outdir, res_day)
        generate_graph_hours(outdir, res_hour)

        logging.info("successfully generated graphs!")

    except linky.LinkyLoginException as exc:
        logging.error(exc)
        sys.exit(1)

    except linky.LinkyServiceException as exc:
        logging.error(exc)
        sys.exit(1)
Exemplo n.º 4
0
def main():
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
    try:
        DATEDEBUT = os.environ['LINKY_DATE_DEBUT']
        DATEFIN = os.environ['LINKY_DATE_FIN']
    except:
        DATEDEBUT = ""
        DATEFIN = ""

    try:
        logging.info("logging in as %s...", USERNAME)
        token = linky.login(USERNAME, PASSWORD)
        logging.info("logged in successfully!")
        logging.info("retreiving data...")

        today = datetime.date.today()

        if TYPEDATA == "year":
            res_year = linky.get_data_per_year(token)
            try:
                export_years_values(res_year)
            except Exception:
                logging.info("years values non exported")

        elif TYPEDATA == "month":
            res_month = linky.get_data_per_month(
                token, dtostr(today - relativedelta(months=11)), dtostr(today))
            try:
                export_months_values(res_month)
            except Exception:
                logging.info("months values non exported")

        elif TYPEDATA == "day":
            res_day = linky.get_data_per_day(
                token, dtostr(today - relativedelta(days=1, months=1)),
                dtostr(today - relativedelta(days=1)))
            try:
                export_days_values(res_day)
            except Exception:
                logging.info("days values non exported")

        elif TYPEDATA == "hour":
            if DATEDEBUT == "":
                DATEDEBUT = dtostr(today - relativedelta(days=1))
            if DATEFIN == "":
                DATEFIN = dtostr(today)
            res_hour = linky.get_data_per_hour(token, DATEDEBUT, DATEFIN)
            try:
                export_hours_values(res_hour)
            except Exception as exc:
                logging.error(exc)

        logging.info("ok")

    except linky.LinkyLoginException as exc:
        logging.error(exc)
        sys.exit(1)
Exemplo n.º 5
0
def main():
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

    try:
        logging.info("logging in as %s...", USERNAME)
        token = linky.login(USERNAME, PASSWORD)
        logging.info("logged in successfully!")

        logging.info("retreiving data...")
        today = datetime.date.today()
        logging.info("arg "+sys.argv[1])
        mmonth     = int(sys.argv[1])
        mmonthnext = int(sys.argv[1])+1
        logging.info(dtostr(today - relativedelta(days=1, months=mmonth)))
        logging.info(dtostr(today - relativedelta(days=1, months=mmonthnext)))
        

        # 12 months ago - today
        res_month = linky.get_data_per_month(token, dtostr(today - relativedelta(months=11)), \
                                             dtostr(today))


        # One month ago - yesterday
        res_day = linky.get_data_per_day(token, dtostr(today - relativedelta(days=1, months=mmonthnext)), \
                                         dtostr(today - relativedelta(days=1, months=mmonth)))

        

        logging.info("got data!")
############################################
		# Export of the JSON files, with exception handling as Enedis website is not robust and return empty data often

        try:
            export_days_values(res_day)
        except Exception:
            logging.info("days values non exported")


############################################
 
    except linky.LinkyLoginException as exc:
        logging.error(exc)
        sys.exit(1)
Exemplo n.º 6
0
def main():
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

    try:
        logging.info("logging in as %s...", USERNAME)
        token = linky.login(USERNAME, PASSWORD)
        logging.info("logged in successfully!")

        logging.info("retreiving data...")
        today = datetime.date.today()
        logging.info("arg "+sys.argv[1])
        mmonth = int(sys.argv[1])
        mmonthnext = int(sys.argv[1])+1
        logging.info(dtostr(today - relativedelta(days=1, months=mmonth)))
        logging.info(dtostr(today - relativedelta(days=1, months=mmonthnext)))

        # 12 months ago - today
        res_month = linky.get_data_per_month(token, dtostr(today - relativedelta(months=11)),
                                             dtostr(today))

        # One month ago - yesterday
        res_day = linky.get_data_per_day(token, dtostr(today - relativedelta(days=1, months=mmonthnext)),
                                         dtostr(today - relativedelta(days=1, months=mmonth)))

        logging.info("got data!")
        ############################################
        # Export of the JSON files, with exception handling as Enedis website is not robust and return empty data often

        try:
            export_days_values(res_day)
        except Exception:
            logging.info("days values non exported")

        ############################################

    except linky.LinkyLoginException as exc:
        logging.error(exc)
        sys.exit(1)
Exemplo n.º 7
0
                                params['influx']['port'],
                                params['influx']['username'],
                                params['influx']['password'],
                                params['influx']['db'],
                                ssl=params['influx']['ssl'],
                                verify_ssl=params['influx']['verify_ssl'])
        logging.info("logged in InfluxDB Server Host %s succesfully",
                     params['influx']['host'])
    except:
        logging.error("unable to login on %s", params['influx']['host'])
        sys.exit(1)

    # Try to log in Enedis API
    try:
        logging.info("logging in Enedis URI %s...", linky.API_BASE_URI)
        token = linky.login(params['enedis']['username'],
                            params['enedis']['password'])
        logging.info("logged in successfully!")
    except linky.LinkyLoginException as exc:
        logging.error("unable to login on %s : %s", linky.API_BASE_URI, exc)
        sys.exit(1)

    # Calculate start/endDate and firstTS for data to request/parse
    if args.last:
        startDate = _getStartDateInfluxDb(client)
        firstTS = datetime.datetime.strptime(startDate, '%d/%m/%Y').timestamp()
    else:
        startDate = _getStartDate(datetime.date.today(), args.days)
        firstTS = _getStartTS(args.days)

    endDate = _dayToStr(datetime.date.today())
    endTS = datetime.datetime.strptime(endDate, '%d/%m/%Y').timestamp()
Exemplo n.º 8
0
# Linkindle - Linky energy consumption curves on a Kindle display.
# Copyright (C) 2016 Baptiste Candellier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import linky
import os

username = os.environ['LINKY_USERNAME']
password = os.environ['LINKY_PASSWORD']

try:
    print("logging in as " + username + "...")
    token = linky.login(username, password)
    print("logged in successfully")
    res = linky.get_data_per_day(token, '27/10/2016', '30/10/2016')
    print(res)
except LinkyLoginException as e:
    print(e)
Exemplo n.º 9
0
            avg += last
            count += 1

    if count != 0:
        return avg / count, count, last

    return 0, 0, -1


def printValue(val):
    return str(round(val, 2))


print("Getting 01/" + m + "/2018 to 31/" + m + "/2018")
print("logging in as " + ids.username + "...")
token = linky.login(ids.username, ids.password)
print("logged in successfully")
month = linky._get_data(token, linky.R_ID_MONTH, '01/10/2017', '31/10/2018')
day = linky._get_data(token, linky.R_ID_DAY, '01/' + m + '/2018', '31/' + m + '/2018')

if not (month is None or day is None):
    # pprint(month)
    # pprint(day)

    avgMonth, countMonth, lastMonth = geyAvg(month)
    avgDay, countDay, lastDay = geyAvg(day)

    maxMonth = rent / kwhPrice
    maxDay = maxMonth / 31

    marginMonth = (maxMonth - avgMonth) * countMonth