|
1 |
| -#!/usr/bin/python3 |
| 1 | +#!/home/collin/pyv/bin/python |
2 | 2 | ################################################################################
|
3 | 3 | # name: sensor_ucnrs_dri_puller.py
|
4 | 4 | # author: collin bode, email: [email protected]
|
|
74 | 74 |
|
75 | 75 | # stations that only can download 30 days or newer without password
|
76 | 76 | #stations = ['hipk','whpt','sagh','croo','wmtn','barc']
|
77 |
| - |
| 77 | + |
78 | 78 | # Loop through all the stations, webscrape, and parse
|
79 | 79 | for station in stations:
|
80 | 80 | print(station)
|
| 81 | + |
81 | 82 | # Define path and station filename
|
82 |
| - #path = '/data/sensor/UCNRS/' |
83 |
| - path = '/Users/cbode/Documents/GoogleDrive/UCNRS_WeatherStations/DatFiles_DRI/' |
| 83 | + path = '/data/sensor/UCNRS/' |
| 84 | + #path = '/Users/cbode/Documents/GoogleDrive/UCNRS_WeatherStations/DatFiles_DRI/' |
| 85 | + ftdirpath = path+'/dri_time/' |
| 86 | + |
| 87 | + # Check for existance of the time files directory, if not create |
| 88 | + if(os.path.exists(ftdirpath) == False): |
| 89 | + os.makedirs(ftdirpath) |
| 90 | + |
| 91 | + # Define file paths |
84 | 92 | fpath = path+station+'_dri.dat'
|
85 |
| - ftpath = fpath+'.time' # The .time file holds the last timestmap recorded |
| 93 | + ftpath = ftdirpath+station+'_dri.dat.time' # The .time file holds the last timestmap recorded |
86 | 94 |
|
87 | 95 | # Build a header if the file doesn't exist yet and FirstRun wasn't called.
|
88 | 96 | if(os.path.exists(fpath) == False):
|
|
91 | 99 | # TIME - get start datetime to pull data. booFirstRun
|
92 | 100 | time_end = dt.datetime.now()
|
93 | 101 | if(booFirstRun == True):
|
94 |
| - #time_start = dt.datetime.now() - dt.timedelta(days=29) # For 30 day locked stations |
95 |
| - time_start = dt.datetime.strptime('1990-01-01 01:00:00',"%Y-%m-%d %H:%M:%S") |
| 102 | + if(station =='hipk' or station == 'whpt'): |
| 103 | + time_start = dt.datetime.now() - dt.timedelta(days=29) # For 30 day locked stations |
| 104 | + else: |
| 105 | + time_start = dt.datetime.strptime('1990-01-01 01:00:00',"%Y-%m-%d %H:%M:%S") |
96 | 106 | time_start_o = time_start
|
97 | 107 | write_mode = 'w' # new file
|
98 | 108 | booWriteHeader = True
|
|
104 | 114 | time_start_o = dt.datetime.strptime(dtstring,"%Y-%m-%d %H:%M:%S")
|
105 | 115 | time_start = time_start_o - dt.timedelta(days=1) # add a day for safety
|
106 | 116 | ft.close()
|
| 117 | + write_mode = 'a' # append to existing file |
107 | 118 | except:
|
108 | 119 | print(ftpath+" not found or doesn't have valid dates. Skipping...")
|
109 | 120 | continue
|
|
156 | 167 | ############################################################################
|
157 | 168 | # HEADER: Build a new header. Ginger wants as similar to .dat as possible.
|
158 | 169 | if(booWriteHeader == True):
|
159 |
| - row1 = '"TOA5","'+station+'","DRI WRCC webscrape"\n' |
| 170 | + row1 = '"TOA5","'+station+'","DRI WRCC webscrape"' |
160 | 171 | row2 = '"TIMESTAMP","RECORD"'
|
161 | 172 | row3 = '"TS","RN"'
|
162 | 173 | row4 = '"",""'
|
|
0 commit comments