-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_difax_plots.py
executable file
·89 lines (75 loc) · 3 KB
/
get_difax_plots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python3
import os
import shutil
import time
from datetime import timedelta
from datetime import datetime
from ftplib import FTP
products = {'850mb':'/home/disk/data/images/difax/difax_850',
'700mb':'/home/disk/data/images/difax/difax_700',
'500mb':'/home/disk/data/images/difax/difax_500',
'300mb':'/home/disk/data/images/difax/difax_300',
'200mb':'/home/disk/data/images/difax/difax_200'}
tempDir = '/tmp'
catalogPrefix = 'upperair.difax'
# Field Catalog inputs
#ftpCatalogServer = 'catalog.eol.ucar.edu'
#ftpCatalogUser = 'anonymous'
#catalogDestDir = '/pub/incoming/catalog/impacts'
# for testing
ftpCatalogServer = 'ftp.atmos.washington.edu'
ftpCatalogUser = 'anonymous'
ftpCatalogPassword = '[email protected]'
catalogDestDir = 'brodzik/incoming/impacts'
# Open ftp connection to NCAR sever
#catalogFTP = FTP(ftpCatalogServer,ftpCatalogUser)
#catalogFTP.cwd(catalogDestDir)
# For testing
catalogFTP = FTP(ftpCatalogServer,ftpCatalogUser,ftpCatalogPassword)
catalogFTP.cwd(catalogDestDir)
#----------------------
# get today's 1200 data
#----------------------
#nowTime = time.gmtime()
#now = datetime(nowTime.tm_year, nowTime.tm_mon, nowTime.tm_mday,
# nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec)
now = datetime.now()
nowDateStr = now.strftime("%Y%m%d")
for product in products:
os.chdir(products[product])
for file in os.listdir():
if file.startswith(nowDateStr) and file.endswith('200.gif'):
(dateTime,ext) = os.path.splitext(file)
catalogName = catalogPrefix+'.'+dateTime+'.'+product+ext
shutil.copy(file,
tempDir+'/'+catalogName)
# ftp file to catalog location
ftpFile = open(os.path.join(tempDir,catalogName),'rb')
catalogFTP.storbinary('STOR '+catalogName,ftpFile)
ftpFile.close()
# remove file from tempDir
os.remove(os.path.join(tempDir,catalogName))
#-------------------------
# get tomorrow's 0000 data
#-------------------------
#tomorrowTime = time.gmtime()
#tomorrow = datetime(tomorrowTime.tm_year, tomorrowTime.tm_mon, tomorrowTime.tm_mday,
# tomorrowTime.tm_hour, tomorrowTime.tm_min, tomorrowTime.tm_sec)
tomorrow = now + timedelta(1)
tomorrowDateStr = tomorrow.strftime("%Y%m%d")
for product in products:
os.chdir(products[product])
for file in os.listdir():
if file.startswith(tomorrowDateStr) and file.endswith('000.gif'):
(dateTime,ext) = os.path.splitext(file)
catalogName = catalogPrefix+'.'+dateTime+'.'+product+ext
shutil.copy(file,
tempDir+'/'+catalogName)
# ftp file to catalog location
ftpFile = open(os.path.join(tempDir,catalogName),'rb')
catalogFTP.storbinary('STOR '+catalogName,ftpFile)
ftpFile.close()
# remove file from tempDir
os.remove(os.path.join(tempDir,catalogName))
# Close ftp connection
catalogFTP.quit()