main.py 5.18 KB
Newer Older
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
1 2 3 4 5 6 7 8 9
import datetime
import configobj
import pkgutil
import os
import sys
import argparse

import wimcollect.httpddu as httpddu
import wimcollect.sshdmc as sshdmc
10
import wimcollect.common.logger as logger
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
11
import wimcollect.quickviz as quickviz
12
import wimcollect.ftpaeris as ftpaeris
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33


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)

34 35 36
    ftpaeris_col = ftpaeris.Collector()
    ftpaeris_col.download_maido_mf_1h("201913")

37
    httpddu_col = httpddu.Collector()
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
38 39
    httpddu_col.download_picarro(yesterday)

40
    sshdmc_col = sshdmc.Collector()
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
41 42
    sshdmc_col.download_picarro(yesterday)

43
    vizual = quickviz.Visualizator()
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
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
    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)
115 116 117 118
    try:
        httpddu_col.download_picarro(args.day)
    except:
        pass
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
119 120

    sshdmc_col = sshdmc.Collector(config_parser, log)
121 122 123 124
    try:
        sshdmc_col.download_picarro(args.day)
    except:
        pass
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
125 126

    vizual = quickviz.Visualizator(config_parser, log)
127 128 129 130 131 132 133 134
    try:
        vizual.create_data_source_file("DDU", "HIDS2189", args.day)
    except:
        pass
    try:
        vizual.create_data_source_file("DMC", "HIDS2319", args.day)
    except:
        pass
JOSSOUD Olivier's avatar
JOSSOUD Olivier committed
135 136 137 138 139 140 141 142


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


if __name__ == "__main__":
    main()