Files
2025-08-04 14:19:38 +02:00

79 lines
3.1 KiB
Python

from datetime import datetime
class CaliforniaCamera:
def __init__(self, cctv):
self.index = int(cctv['index'])
timestamp = f"{cctv['recordTimestamp']['recordDate']}-{cctv['recordTimestamp']['recordTime']}".replace(":", "-")
self.record_date = datetime.strptime(timestamp, '%Y-%m-%d-%H-%M-%S')
self.timestamp = int(cctv['recordTimestamp']['recordEpoch'])
location = cctv['location']
self.district = location['district']
self.name = location['locationName']
self.place = location['nearbyPlace']
if len(self.place) == 0:
self.place = '---'
self.longitude = float(location['longitude'])
self.latitude = float(location['latitude'])
self.elevation = float(location['elevation'])
self.direction = location['direction']
self.county = location['county']
self.route = location['route']
self.postmile = float(location['postmile'])
self.milepost = float(location['milepost'])
self.in_service = bool(cctv['inService'])
self.images = [cctv['imageData']['static'][img_url_key] for img_url_key in cctv['imageData']['static'].keys()
if str(img_url_key).endswith("URL")]
self.stream_url = cctv['imageData']['streamingVideoURL']
def __str__(self):
return f"CaliforniaCamera: {str(vars(self))}"
class NevadaCamera:
def __init__(self, data):
self.DT_RowId = data['DT_RowId']
self.visible = data['visible']
if len(data["images"]) != 1:
raise ValueError()
image_info = data["images"][0]
if image_info["id"] != int(self.DT_RowId):
raise ValueError()
self.description = image_info["description"]
self.image_url = "https://www.nvroads.com"+ image_info["imageUrl"]
self.video_url = None
if "videoUrl" in image_info.keys():
self.video_url = image_info["videoUrl"]
if data["id"] != int(self.DT_RowId):
raise ValueError()
self.id = data["id"]
self.area_id = data["areaId"]
area = data["area"]
self.area_name = ""
self.parent_area_id = -1
if area is not None:
self.area_name = data["area"]["areaName"]["text"]
if data["area"]["areaId"] != self.area_id:
raise ValueError()
self.parent_area_id = data["area"]["parentArea_AreaId"]
self.roadway = data["roadway"]
self.direction = data["direction"]
self.location = data["location"]
latLng = str(data["latLng"]["geography"]["wellKnownText"])
coordinates = latLng[latLng.find("(")+1:latLng.find(")")].split()
self.latitude = float(coordinates[1])
self.longitude = float(coordinates[0])
self.region = data["region"]
self.state = data["state"]
self.country = ""
if "country" in data.keys():
self.country = data["country"]
self.stream_url = self.video_url
self.index = self.id
self.name = self.roadway
def __str__(self):
return f"NevadaCamera: {str(vars(self))}"