import time from java.util import Collections from java.lang import System from org.das2.fsm import FileStorageModel from org.das2.util.filesystem import FileSystem setScriptDescription('''Demonstrate parsing and formatting of URI_Templates. For parsing, we list a remote website and interpret the times for each file. For formatting, the names are generated.''') setScriptTitle('URI_Templates') # see also https://github.com/autoplot/dev/blob/master/demos/2024/20240802/URI_Templates.jy resourceURI= getParam( 'resourceURI', 'http://autoplot.org/data/C1_CP_EDI_EGD__$Y$m$d_V03.cef', 'example file to load', [ 'data_$Y_$(m)_$(d;delta=7;phasestart=2019-05-05).qds', 'http://autoplot.org/data/C1_CP_EDI_EGD__$Y$m$d_V03.cef', 'C1_CP_EDI_EGD__$Y$m$d_$(enum,values=A|B).cef' ] ) timerange= getParam( 'timerange', '2005-02-12/2005-02-19', 'timerange to load' ) generate= getParam( 'generate', False, 'Generation doesn''t list remote folders', [True,False] ) if ( len(timerange.split(' '))==10 ): # make it easier to use Jon V.'s document "uri_template_test_cases.txt" trs= timerange.split(' ') timerange= '-'.join( trs[0:3] ) + 'T' + ':'.join( trs[3:5] ) + '/' + '-'.join( trs[5:8] ) + 'T' + ':'.join( trs[8:10] ) drtr= DatumRangeUtil.parseTimeRange(timerange) count=0 if ( False ): print params print '# resourceURI='+resourceURI print '# timerange='+timerange print '# generate='+generate print '
' t0= System.currentTimeMillis() if ( generate ): if ( resourceURI.find('$v')>-1 ): print 'Template cannot contain $v.' count=-1 else: tp= TimeParser.create(resourceURI) i1= resourceURI.find('$(enum') if ( i1>-1 ): ix= resourceURI.find('$(enum',i1+6) if (ix>-1 ): print 'Template can only contain one $(enum).' count=-1 else: fh= tp.getFieldHandlerByCode('enum') enums= fh.getValues() id= fh.getId() else: enums= [''] id= '' st= tp.format( drtr.min(), None, Collections.singletonMap( id, enums[0] ) ) dr= tp.parse( st,None ).getTimeRange() print( "search limited to '+timerange+'
' print 'Time Range | Generated filename | |
'+ dr.toString() + ' | '+st + ' | |
Search limited to 10000 results. |
Filename | Time Range | Version |
'+ll + ' | '+tr.toString() + ' | ' + v +' | ' count= count+1 print '