def etoit(station,dayofyear): info=['','','','','','','','','','','','','','','','','','','','','','','',''] for i in range (24): ind=str(i) if os.path.isfile(dayofyear+ind): observation=arch(dayofyear+ind, 'r',0) if len(observation)>3: #print observation if len(observation[1])>5: #there's data in the file info[i]="\nTimestamp: "+ind+ etowind20.etowind(observation,station) elif isinstance(eval(observation[3]), dict): #ver si hay datos de google #si hay datos de google llamar a etwind con los datos #print 'Checking Google data \n' gdat=eval(observation[3]) try: if gdat['current_conditions']['temp_c']!='': info[i]="\nTimestamp: "+ind+ etowind20.etowind(gdat,station) #print 'Valid Google data\n' except: print 'Invalid Google data\n' #print observation [3] #crear nombre de archivo indice dex=dayofyear+'.dex' #guardar datos f=open(dex,'w') for i in range (len(info)): f.write(info[i]) f.close() dexinfo=arch(dex,'r',0) #si hay datos en el indice llamar a etorad (esto deberia correr una vez con todos los datos del dia if not len(dexinfo)==0: arch(dex,'a',etrad10.etorad(dexinfo,station,dex)) #writes timestamp
basename=str(now.year)+str(cday(now)) #General filename foo=str(now.hour) entry_name=basename+foo #hourly report name if not present(entry_name): arch(entry_name, 'w', 'Metar\n'+str(obs)+'\nGoogle\n' + str(goo)) #Creates file YYYYDDDHH info="\nTimestamp: "+foo+ etowind20.etowind(arch(entry_name, 'r',0),station)#Creates info for Index file if os.path.isfile(basename+".dex"): #file exists!, add new info arch(basename+".dex",'a',info) else: #newday (or new station), calculate etorad for last day (if info present) for files in os.listdir('.'): #Previous info? if fnmatch.fnmatch(files, '*dex'): #Get last data and calculate etorad last_one=get_last_Index('.') arch(last_one,'a',etrad10.etorad(arch(last_one, 'r',0),station,last_one)) arch(basename+".dex", 'w',info) #writes info to Index file os.chdir(home)