Skip to content

Commit b269bc3

Browse files
committed
DBC22-6929: pull local weather station code to current weather
1 parent 35ae122 commit b269bc3

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/backend/apps/consumer/processor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ def process_camera_rows(rows):
318318
'cam_maintenanceis_on_demand': row.cam_maintenanceis_on_demand if hasattr(row, 'cam_maintenanceis_on_demand') else False,
319319
'is_new': row.isnew if hasattr(row, 'isnew') else False,
320320
'seq': row.seq if hasattr(row, 'seq') else 0,
321+
'cam_locationsweather_station': row.cam_locationsweather_station if hasattr(row, 'cam_locationsweather_station') else '',
321322

322323
}
323324
camera_list.append(camera_obj)

src/backend/apps/webcam/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class CameraSource(models.Model):
167167
isnew = models.BooleanField(default=False)
168168
cam_maintenanceis_on_demand = models.BooleanField(default=False)
169169
seq = models.IntegerField(blank=True, null=True)
170+
cam_locationsweather_station = models.CharField(max_length=10, blank=True, null=True)
170171

171172
class Meta:
172173
db_table = 'Cams_Live'

src/backend/apps/webcam/tasks.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def update_cam_from_sql_db(id: int, current_time: datetime.datetime):
9999
credit=F('cam_internetcredit'),
100100
dbc_mark=F('cam_internetdbc_mark'),
101101
isNew=F('isnew'),
102+
cam_locations_weather_station=F('cam_locationsweather_station'),
102103
)
103104
.values(
104105
'id',
@@ -114,12 +115,15 @@ def update_cam_from_sql_db(id: int, current_time: datetime.datetime):
114115
'credit',
115116
'dbc_mark',
116117
'isNew',
118+
'cam_locations_weather_station',
117119
)
118120
.first()
119121
)
120122

121123
if cam:
122124
update_webcam_db(id, cam)
125+
print('bruce test here to get code')
126+
update_current_weather_code(id, cam)
123127
return True
124128
else:
125129
return False
@@ -142,6 +146,16 @@ def format_region_name(region_name):
142146
return ''.join(result)
143147

144148

149+
def update_current_weather_code(cam_id: int, cam_data: dict):
150+
cam = Webcam.objects.get(id=cam_id)
151+
local_weather_station_id = cam.local_weather_station_id
152+
code = cam_data.get("cam_locations_weather_station")
153+
update_data = {
154+
"code": code,
155+
}
156+
CurrentWeather.objects.filter(id=local_weather_station_id).update(**update_data)
157+
return True
158+
145159
def update_webcam_db(cam_id: int, cam_data: dict):
146160
time_now_utc = datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%d%H%M%S%f")[:-3]
147161
camera_status = calculate_camera_status(cam_id, time_now_utc)

0 commit comments

Comments
 (0)