Ejemplo 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)
Ejemplo 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)
Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 5
0
        firstTS = _getStartTS(args.days)

    endDate = _dayToStr(datetime.date.today())
    endTS = datetime.datetime.strptime(endDate, '%d/%m/%Y').timestamp()
    if firstTS >= endTS:
        logging.error(
            "No data available as startDate (%s) is not before endDate (%s)",
            str(startDate), str(endDate))
        sys.exit(1)

    # Try to get data from Enedis API
    try:
        logging.info("get Data from Enedis from {0} to {1}".format(
            startDate, endDate))
        # Get result from Enedis by 30m
        resEnedis = linky.get_data_per_hour(token, startDate, endDate)
        if (args.verbose):
            pp.pprint(resEnedis)
    except:
        logging.error("unable to get data from enedis")
        sys.exit(1)

    if resEnedis['etat']['valeur'] == 'nonActive':
        logging.error(
            "Data from enedis are in state 'nonActive'. So graphe will be empty, no value to push"
        )
        sys.exit(1)

    # When we have all values let's start parse data and pushing it
    jsonInflux = []
    for d in resEnedis['graphe']['data']: