|
53 | 53 | import os
|
54 | 54 |
|
55 | 55 | # Boolean controls for script. Cron job mode is false, false, true.
|
56 |
| -booFirstRun = True # True = Download all data available from 1990 until now |
| 56 | +booFirstRun = False # True = Download all data available from 1990 until now |
57 | 57 | # DRI controlled sites only can download 30 days,
|
58 | 58 | # unless you have 'secret' password.
|
59 | 59 | # False(default) = just download the last 24 hours
|
60 | 60 | # booWriteHeader will automatically be set to True.
|
61 |
| -booWriteHeader = True # True = Get Long Header parse into LoggerNet header. |
| 61 | +booWriteHeader = True # True = Get Long Header parse into LoggerNet header. |
62 | 62 | # False(default) = No header, just data.
|
63 |
| -booDownloadData = True # True(default). False will only download headers. |
| 63 | +booDownloadData = False # True(default). False will only download headers. |
64 | 64 |
|
65 | 65 | # WRCC DRI Website
|
66 | 66 | website = 'http://www.wrcc.dri.edu/cgi-bin/wea_list2.pl'
|
|
77 | 77 |
|
78 | 78 | # Loop through all the stations, webscrape, and parse
|
79 | 79 | for station in stations:
|
80 |
| - print(station) |
| 80 | + #print(station) |
81 | 81 |
|
82 | 82 | # Define path and station filename
|
83 | 83 | path = '/data/sensor/UCNRS/'
|
84 | 84 | #path = '/Users/cbode/Documents/GoogleDrive/UCNRS_WeatherStations/DatFiles_DRI/'
|
85 |
| - ftdirpath = path+'/dri_time/' |
| 85 | + ftdirpath = path+'dri_time/' |
86 | 86 |
|
87 | 87 | # Check for existance of the time files directory, if not create
|
88 | 88 | if(os.path.exists(ftdirpath) == False):
|
|
110 | 110 | try:
|
111 | 111 | ft = open(ftpath,'r') # open .time file and get last datetime pulled
|
112 | 112 | dtstring = (ft.read()).strip()
|
113 |
| - print(station+' last date: '+dtstring) |
| 113 | + #print(station+' last date: '+dtstring) |
114 | 114 | time_start_o = dt.datetime.strptime(dtstring,"%Y-%m-%d %H:%M:%S")
|
115 | 115 | time_start = time_start_o - dt.timedelta(days=1) # add a day for safety
|
116 | 116 | ft.close()
|
|
172 | 172 | row3 = '"TS","RN"'
|
173 | 173 | row4 = '"",""'
|
174 | 174 | j = 0
|
| 175 | + t = 0 # how many duplicates of Min TC 10m are there? |
175 | 176 | booWriteHeader = False
|
176 | 177 | for row in received_data:
|
177 | 178 | #print(row)
|
|
183 | 184 | booWriteHeader = True
|
184 | 185 | # DRI long headers are sentence descriptions
|
185 | 186 | # This segment shortens them to field names with no unusual characters
|
186 |
| - fieldname = fields[0].strip() |
| 187 | + fieldname = fields[0][1:-1] |
| 188 | + fieldname = fieldname.replace(':','') |
| 189 | + fieldname = fieldname.strip() |
187 | 190 | fieldname = fieldname.replace('"','')
|
188 | 191 | fieldname = fieldname.replace(' ','_')
|
189 | 192 | fieldname = fieldname.replace('_in.','_Inches')
|
|
200 | 203 | fieldname = fieldname.replace('Minimum','Min')
|
201 | 204 | fieldname = fieldname.replace('Temperature','Temp')
|
202 | 205 | fieldname = fieldname.replace('temperature','Temp')
|
203 |
| - fieldname = fieldname.replace('Average','Ave') |
| 206 | + fieldname = fieldname.replace('Ave_','Avg_') |
| 207 | + fieldname = fieldname.replace('Average','Avg') |
204 | 208 | fieldname = fieldname.replace('Miscellaneous','Misc')
|
205 | 209 | fieldname = fieldname.replace('Identification','ID')
|
206 | 210 | fieldname = fieldname.replace('Standard_Deviation','Std Dev')
|
207 | 211 | fieldname = fieldname.replace('Standard_Deveation','Std Dev')
|
| 212 | + fieldname = fieldname.replace('_mag/arcsec2','_mag') |
| 213 | + fieldname = fieldname.replace('/','') |
| 214 | + fieldname = fieldname.replace('\\','') |
| 215 | + |
| 216 | + # Fix Thermocouple duplicate |
| 217 | + if(fieldname == 'Min_Temp_Thermocouple_10_m'): |
| 218 | + t += 1 |
| 219 | + if(t == 2): |
| 220 | + fieldname = fieldname.replace('Min','Avg') |
208 | 221 | # Field units are inserted for posterity, but not used by loader
|
209 | 222 | fieldunits = fields[1].strip()
|
210 | 223 | fieldunits = (fieldunits[1:len(fieldunits)-1]).strip()
|
|
240 | 253 | # Merge date and time into TIMESTAMP
|
241 | 254 | timestamp = 'GEORGE'
|
242 | 255 | if(booDownloadData == True):
|
243 |
| - print('____Data next____') |
| 256 | + #print('____Data next____') |
244 | 257 | for row in received_data:
|
245 | 258 | if(len(row) > 0):
|
246 | 259 | fields = row.split(",")
|
|
257 | 270 | if(ts > time_start_o):
|
258 | 271 | fout.write(newrow)
|
259 | 272 | else:
|
260 |
| - print(station+' redundant timestamp:',timestamp,' < ',time_start_o) |
| 273 | + pass |
| 274 | + #print(station+' redundant timestamp:',timestamp,' < ',time_start_o) |
261 | 275 | #print(newrow)
|
262 | 276 | #else:
|
263 | 277 | # print('BAD HTML! ')
|
|
266 | 280 | ft = open(ftpath,'w')
|
267 | 281 | ft.write(timestamp+"\n")
|
268 | 282 | ft.close()
|
269 |
| - print(station+" downloaded and writen to file") |
| 283 | + #print(station+" downloaded and writen to file") |
270 | 284 | else:
|
271 | 285 | print('WARNING! '+station+' did not have any values to download.')
|
272 | 286 | # Finish up with station
|
|
0 commit comments