main.py 4.95 KB
Newer Older
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
import datetime
import configobj
import pkgutil
import os
import sys
import argparse

import wimcollect.httpddu as httpddu
import wimcollect.sshdmc as sshdmc
import wimcollect.logger as logger
import wimcollect.quickviz as quickviz


def main():

    # Configuration file
    pkgpath = os.path.dirname(pkgutil.get_loader("wimcollect").path)
    conf_file_path = os.path.join(pkgpath, "config", "settings.ini")
    if not os.path.exists(conf_file_path):
        sys.stderr.write("Configuration file not found in [" + conf_file_path + "]")
        return
    config_parser = configobj.ConfigObj(conf_file_path)

    # Logger
    log = logger.Logger(config_parser)

    log.write(instrument="", message="------------------------------------------------------------------")
    log.write(instrument="", message=" ".join(sys.argv))
    log.write(instrument='', message="------------------------------------------------------------------")

    yesterday = datetime.datetime.now() - datetime.timedelta(1)

    httpddu_col = httpddu.Collector(config_parser, log)
    httpddu_col.download_picarro(yesterday)

    sshdmc_col = sshdmc.Collector(config_parser, log)
    sshdmc_col.download_picarro(yesterday)

    vizual = quickviz.Visualizator(config_parser, log)
    vizual.create_data_source_file("DDU", "HIDS2189", yesterday)
    vizual.create_data_source_file("DMC", "HIDS2319", yesterday)

    #
    # # Parse CLI arguments
    # parser = argparse.ArgumentParser(description='Launch a push.')
    # parser.add_argument('-i', '--instruments',
    #                     nargs='+',
    #                     default="picarro",
    #                     choices=["picarro", "hobo"])
    # parser.add_argument('-a', '--actions',
    #                     nargs='+',
    #                     default=["compress", "send"],
    #                     choices=["compress", "send"])
    # parser.add_argument('-fd', '--firstday', default=None, type=format_date,
    #                     help="First day (in ISO format YYYY-MM-DD) of the desired timeframe to be compressed.")
    # parser.add_argument('-ld', '--lastday', default=None, type=format_date,
    #                     help="Last day (in ISO format YYYY-MM-DD) of the desired timeframe to be compressed.")
    # parser.add_argument('-d', '--day', default=None, type=format_date,
    #                     help="Day (in ISO format YYYY-MM-DD) whose Picarro data whould be compressed. "
    #                          "Note: single-day selection is not applicable for Hobo, used --firstday instead.")
    # args = parser.parse_args()
    #
    # # Compress
    # if "compress" in args.actions:
    #     # Picarro
    #     if "picarro" in args.instruments:
    #         pic_comp = ftpcea.Compressor(config_parser, log)
    #         if args.firstday is not None:
    #             pic_comp.compress_timeframe(first_day=args.firstday, last_day=args.lastday)
    #         elif args.day is not None:
    #             pic_comp.compress_single_day(day=args.day)
    #         else:
    #             pic_comp.compress_changed()
    #
    #     # Hobo
    #     if "hobo" in args.instruments:
    #         hobo_comp = hobo.Compressor(config_parser, log)
    #         if args.firstday is not None:
    #             hobo_comp.compress_timeframe(first_day=args.firstday, last_day=args.lastday)
    #         elif args.day is not None:
    #             sys.stderr.write("Parameter 'day' is not useable with Hobo. Use '--firstday' instead.")
    #         else:
    #             hobo_comp.compress_changed()
    #
    # # Send
    # if "send" in args.actions:
    #     sender = ftpsender.FtpSender(config_parser, log)
    #     sender.send_all()


def quickviz_antarctica():
    # Configuration file
    pkgpath = os.path.dirname(pkgutil.get_loader("wimcollect").path)
    conf_file_path = os.path.join(pkgpath, "config", "settings.ini")
    if not os.path.exists(conf_file_path):
        sys.stderr.write("Configuration file not found in [" + conf_file_path + "]")
        return
    config_parser = configobj.ConfigObj(conf_file_path)

    # Logger
    log = logger.Logger(config_parser)

    yesterday = datetime.datetime.now() - datetime.timedelta(1)
    # Parse CLI arguments
    parser = argparse.ArgumentParser(description='Generate data for PIcarro\' s quick calibration visualization.')
    parser.add_argument('-d', '--day', default=yesterday, type=format_date,
                        help="Day (in ISO format YYYY-MM-DD) which should be processed.")
    args = parser.parse_args()

    httpddu_col = httpddu.Collector(config_parser, log)
    httpddu_col.download_picarro(args.day)

    sshdmc_col = sshdmc.Collector(config_parser, log)
    sshdmc_col.download_picarro(args.day)

    vizual = quickviz.Visualizator(config_parser, log)
    vizual.create_data_source_file("DDU", "HIDS2189", args.day)
    vizual.create_data_source_file("DMC", "HIDS2319", args.day)


def format_date(string: str) -> datetime.date:
    return datetime.datetime.strptime(string, "%Y-%m-%d").date()


if __name__ == "__main__":
    main()