import requests
from time import time
from time import sleep
from contextlib import chdir
import copy

headerz = {'Accept' : 'image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5', 'Accept-Encoding' :
	'gzip, deflate, br, zstd', 'Accept-Language' :
	'en-CA,en-US;q=0.9,en;q=0.8', 'Referer' :
	'https://www.portvancouver.com/' }

milliseconds = int(time() * 1000)
x1 = requests.Response()
x2 = requests.Response()
x3 = requests.Response()
x4 = requests.Response()
x5 = requests.Response()
x6 = requests.Response()
x7 = requests.Response()
x8 = requests.Response()
x9 = requests.Response()
x10 = requests.Response()
x11 = requests.Response()
x12 = requests.Response()
x13 = requests.Response()
x14 = requests.Response()
x15 = requests.Response()
x16 = requests.Response()
x17 = requests.Response()
x18 = requests.Response()
x19 = requests.Response()


astr1 = "https://ehub.portvancouver.com/Webcams/Photos/CommOver?" 
astr2 = "https://ehub.portvancouver.com/webcams/Photos/DPWExitWest?" 
astr3 = "https://ehub.portvancouver.com/Webcams/Photos/CentermMainGates?" 
astr4 = "https://ehub.portvancouver.com/Webcams/Photos/VantermEntrance?" 
astr5 = "https://ehub.portvancouver.com/Webcams/Photos/VantermGates?" 
astr6 = "https://ehub.portvancouver.com/Webcams/Photos/ClarkEntrance?" 
astr7 = "https://ehub.portvancouver.com/Webcams/Photos/ColumbiaContainerCrossing?" 
astr8 = "https://ehub.portvancouver.com/webcams/Photos/TerminalDock?" 
astr9 = "https://ehub.portvancouver.com/Webcams/Photos/CommEntrance?" 
astr10 = "https://ehub.portvancouver.com/Webcams/Photos/CommOverMcGill?" 
astr11 = "https://ehub.portvancouver.com/Webcams/Photos/CameraDP_FS1?" 
astr12 = "https://ehub.portvancouver.com/Webcams/Photos/DeltaportGate1?" 
astr13 = "https://ehub.portvancouver.com/Webcams/Photos/DMSWest?" 
astr14 = "https://ehub.portvancouver.com/Webcams/Photos/FSMainIntersection?" 
astr15 = "https://ehub.portvancouver.com/Webcams/Photos/FSTruckInGate?" 
astr16 = "https://ehub.portvancouver.com/Webcams/Photos/FSVACSGates?" 
astr17 = "https://ehub.portvancouver.com/Webcams/Photos/FS5TrackCrossing?" 
astr18 = "https://ehub.portvancouver.com/Webcams/Photos/PortsideNo8?" 
astr19 = "https://ehub.portvancouver.com/Webcams/Photos/PortsideCoast2000?" 

image_name = "image"

def acquireImage(request_string, folder_name, response):
	global image_check
	image_check = copy.deepcopy(response)
	response = requests.get(request_string, headers=headerz)
	if response.content != image_check.content:
		with chdir(folder_name):
			if response.status_code == 200:
				with open(image_name, 'wb') as f:
					f.write(response.content)
	else:
		print("Copy detected and removed (folder_name)")


def getTimeAndName():
	milliseconds = int(time() * 1000)
	global image_name
	image_name = "image" + str(milliseconds) + ".jpg"

while True:
	getTimeAndName()
	acquireImage(astr1 + str(milliseconds), 'Commissioner entrance', x1)
	getTimeAndName()
	acquireImage(astr2 + str(milliseconds), 'Waterfront_road Centerm crossing', x2)
	getTimeAndName()
	acquireImage(astr3 + str(milliseconds), 'Centerm in gate', x3)
	getTimeAndName()
	acquireImage(astr4 + str(milliseconds), 'Vanterm Alliance Grain Terminal crossing', x4)
	getTimeAndName()
	acquireImage(astr5 + str(milliseconds), 'Vanterm in gate', x5)
	getTimeAndName()
	acquireImage(astr6 + str(milliseconds), 'Clark Drive overpass', x6)
	getTimeAndName()
	acquireImage(astr7 + str(milliseconds), 'Columbia Container - crossing', x7)
	getTimeAndName()
	acquireImage(astr8 + str(milliseconds), 'Terminal dock', x8)
	getTimeAndName()
	acquireImage(astr9 + str(milliseconds), 'Commissioner truck staging', x9)
	getTimeAndName()
	acquireImage(astr10 + str(milliseconds), 'Commissioner street overpass', x10)
	getTimeAndName()
	acquireImage(astr11 + str(milliseconds), 'Deltaport causeway', x11)
	getTimeAndName()
	acquireImage(astr12 + str(milliseconds), 'Deltaport gate 1', x12)
	getTimeAndName()
	acquireImage(astr13 + str(milliseconds), 'Delta truck staging', x13)
	getTimeAndName()
	acquireImage(astr14 + str(milliseconds), 'Fraser Surrey main intersection', x14)
	getTimeAndName()
	acquireImage(astr15 + str(milliseconds), 'Fraser Surrey in gate', x15)
	getTimeAndName()
	acquireImage(astr16 + str(milliseconds), 'Fraser Surrey VACS gates', x16)
	getTimeAndName()
	acquireImage(astr17 + str(milliseconds), 'Fraser Surrey track crossing', x17)
	getTimeAndName()
	acquireImage(astr18 + str(milliseconds), 'PortsideBlundellNo.8 road intersection', x18)
	getTimeAndName()
	acquireImage(astr19 + str(milliseconds), 'Portside road - westbound', x19)


	
	

	print("Scanned")
