station_save_dir, "{0}_meta.xml".format(stem + station)
                    ),
                    write_station=True,
                )

            # --> write log file
            log_fn = os.path.join(
                station_save_dir, "{0}_Archive.log".format(stem + station)
            )
            with open(log_fn, "w") as log_fid:
                log_fid.write("\n".join(output))

            ### Upload data to science base
            if upload_data:
                sb_item = archive.sb_upload_data(
                    page_id, station_save_dir, username, password
                )
            ### caluclate end time
            s_et = datetime.datetime.now()
            station_diff = s_et - s_st

            print(
                "--> Archived station {0}, took {1}:{2:02.2f}, finished at {3}".format(
                    station,
                    int(station_diff.total_seconds() // 60),
                    station_diff.total_seconds() % 60,
                    datetime.datetime.ctime(datetime.datetime.now()),
                )
            )
    except Exception as e:
        print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
Beispiel #2
0
page_id = '5ad77f06e4b0e2c2dd25e798'
username = '******'
# =============================================================================
# Upload data
# =============================================================================
if __name__ == "__main__":
    
    password = getpass.getpass()
    st = datetime.datetime.now()
    station = sys.argv[1]
    if station.find('[') == 0:
        station_list = station.replace('[', '').replace(']', '').split(',')
        station_list = [ss.strip() for ss in station_list]
    else:
        station_list = [station]
    
    print(station_list, type(station_list))
    for sb_station in station_list:
        station_item = archive.sb_upload_data(page_id,
                                              os.path.join(archive_dir, sb_station),
                                              username,
                                              password)  
    et = datetime.datetime.now()
    t_diff = et-st
    print('---> Archived {0}'.format(station))
    print('     Took {0:.0f}:{1:02.2f}'.format(int(t_diff.total_seconds()//60),
                                              t_diff.total_seconds()%60))
    print('     Ended at {0}'.format(datetime.datetime.ctime(datetime.datetime.now())))