def downloadCycle(self, datecycle, cycle, forecast): self.downloading = True filename = "WAFS_blended_%sf%02d.grib2" % (datecycle, forecast) url = "%s/gfs.%s/%s" % (self.baseurl, datecycle, filename) cachefile = os.sep.join(['wafs', '%s_%s' % (datecycle, filename)]) path = os.sep.join([self.conf.cachepath, 'wafs']) if not os.path.exists(path): os.makedirs(path) #print cachefile, url self.download = AsyncDownload(self.conf, url, cachefile)
def downloadCycle(self, cycle, timestamp): self.downloading = True cachepath = os.sep.join([self.conf.cachepath, 'metar']) if not os.path.exists(cachepath): os.makedirs(cachepath) prefix = self.conf.metar_source if self.conf.metar_source == 'NOAA': url = self.NOAA_METAR_URL elif self.conf.metar_source == 'VATSIM': url = self.VATSIM_METAR_URL elif self.conf.metar_source == 'IVAO': url = self.IVAO_METAR_URL cachefile = os.sep.join(['metar', '%s_%d_%sZ.txt' % (prefix, timestamp, cycle)]) self.download = AsyncDownload(self.conf, url, cachefile)
def __init__(self, conf): self.conf = conf self.cachepath = os.sep.join([conf.cachepath, 'metar']) if not os.path.exists(self.cachepath): os.makedirs(self.cachepath) self.database = os.sep.join([self.cachepath, 'metar.db']) self.th_db = False # Weather variables self.weather = None self.reparse = True # Download flags self.ms_download = False self.downloading = False self.next_metarRWX = time.time() + 30 # Main db connection, create db if doens't exist createdb = True if os.path.exists(self.database): createdb = False self.connection = self.dbConnect(self.database) self.cursor = self.connection.cursor() if createdb: self.conf.ms_update = 0 self.dbCreate(self.connection) # Metar stations update if (time.time() - self.conf.ms_update) > self.STATION_UPDATE_RATE * 86400: self.ms_download = AsyncDownload( self.conf, self.METAR_STATIONS_URL, os.sep.join(['metar', 'stations.txt'])) self.last_latlon, self.last_station, self.last_timestamp = [False] * 3
def downloadCycle(self, datecycle, cycle, forecast): ''' Downloads the requested grib file ''' filename = 'gfs.t%02dz.pgrb2full.0p50.f0%02d' % (cycle, forecast) path = os.sep.join([self.conf.cachepath, 'gfs']) cachefile = os.sep.join(['gfs', '%s_%s.grib2' % (datecycle, filename)]) if cachefile == self.lastgrib: # No need to download return if not os.path.exists(path): os.makedirs(path) if self.downloading == True: if not self.download.q.empty(): #Finished downloading lastgrib = self.download.q.get() # Dowload success if lastgrib: if not self.conf.keepOldFiles and self.conf.lastgrib: util.remove( os.sep.join( [self.conf.cachepath, self.conf.lastgrib])) self.lastgrib = lastgrib self.conf.lastgrib = self.lastgrib self.newGrib = True #print "new grib file: " + self.lastgrib else: # Wait a minute self.downloadWait = 60 self.downloading = False elif self.conf.download and self.downloadWait < 1: # Download new grib ## Build download url params = self.params dir = 'dir=%%2Fgfs.%s' % (datecycle) params.append(dir) params.append('file=' + filename) # add variables for level in self.levels: params.append('lev_' + level + '=1') for var in self.variables: params.append('var_' + var + '=1') url = self.baseurl + '&'.join(params) #print 'XPGFS: downloading %s' % (url) self.downloading = True self.download = AsyncDownload(self.conf, url, cachefile) return False