meteortools.ukmondb.ECSVhandler
1# Copyright (C) 2018-2023 Mark McIntyre 2 3import requests 4import os 5 6 7def getECSVs(stationID, dateStr, savefiles=False, outdir='.'): 8 """ 9 Retrieve a detection in ECSV format for the specified date 10 11 Arguments: 12 stationID: [str] RMS Station ID code 13 dateStr: [str] Date/time to retrieve for in ISO1601 format 14 eg 2021-07-17T02:41:05.05 15 16 Keyword Arguments: 17 saveFiles: [bool] save to file, or print to screen. Default False 18 outdir: [str] path to save files into. Default '.' 19 """ 20 apiurl='https://api.ukmeteors.co.uk/getecsv?stat={}&dt={}' 21 res = requests.get(apiurl.format(stationID, dateStr)) 22 ecsvlines='' 23 if res.status_code == 200: 24 rawdata=res.text.strip() 25 if len(rawdata) > 10: 26 ecsvlines=rawdata.split('\n') # convert the raw data into a python list 27 if savefiles is True: 28 os.makedirs(outdir, exist_ok=True) 29 fnamebase = dateStr.replace(':','_').replace('.','_') # create an output filename 30 j=0 31 outf = False 32 for li in ecsvlines: 33 if 'issue getting data' in li: 34 print(li) 35 return li 36 if '# %ECSV' in li: 37 if outf is not False: 38 outf.close() 39 j=j+1 40 fname = fnamebase + f'_ukmda_{stationID}_M{j:03d}.ecsv' 41 outf = open(os.path.join(outdir, fname), 'w') 42 print('saving to ', os.path.join(outdir,fname)) 43 if outf: 44 outf.write(f'{li}\n') 45 else: 46 print('no ECSV marker found in data') 47 else: 48 print('no error, but no data returned') 49 else: 50 print(res.status_code) 51 return ecsvlines
def
getECSVs(stationID, dateStr, savefiles=False, outdir='.'):
8def getECSVs(stationID, dateStr, savefiles=False, outdir='.'): 9 """ 10 Retrieve a detection in ECSV format for the specified date 11 12 Arguments: 13 stationID: [str] RMS Station ID code 14 dateStr: [str] Date/time to retrieve for in ISO1601 format 15 eg 2021-07-17T02:41:05.05 16 17 Keyword Arguments: 18 saveFiles: [bool] save to file, or print to screen. Default False 19 outdir: [str] path to save files into. Default '.' 20 """ 21 apiurl='https://api.ukmeteors.co.uk/getecsv?stat={}&dt={}' 22 res = requests.get(apiurl.format(stationID, dateStr)) 23 ecsvlines='' 24 if res.status_code == 200: 25 rawdata=res.text.strip() 26 if len(rawdata) > 10: 27 ecsvlines=rawdata.split('\n') # convert the raw data into a python list 28 if savefiles is True: 29 os.makedirs(outdir, exist_ok=True) 30 fnamebase = dateStr.replace(':','_').replace('.','_') # create an output filename 31 j=0 32 outf = False 33 for li in ecsvlines: 34 if 'issue getting data' in li: 35 print(li) 36 return li 37 if '# %ECSV' in li: 38 if outf is not False: 39 outf.close() 40 j=j+1 41 fname = fnamebase + f'_ukmda_{stationID}_M{j:03d}.ecsv' 42 outf = open(os.path.join(outdir, fname), 'w') 43 print('saving to ', os.path.join(outdir,fname)) 44 if outf: 45 outf.write(f'{li}\n') 46 else: 47 print('no ECSV marker found in data') 48 else: 49 print('no error, but no data returned') 50 else: 51 print(res.status_code) 52 return ecsvlines
Retrieve a detection in ECSV format for the specified date
Arguments:
stationID: [str] RMS Station ID code
dateStr: [str] Date/time to retrieve for in ISO1601 format
eg 2021-07-17T02:41:05.05
Keyword Arguments:
saveFiles: [bool] save to file, or print to screen. Default False
outdir: [str] path to save files into. Default '.'