-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageDownloader.py
599 lines (504 loc) · 28.7 KB
/
imageDownloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
from os.path import exists
from requests import get
from os import makedirs
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from time import sleep
# from subprocess import CREATE_NO_WINDOW
# Create directories if they don't exist
makedirs('./assets/images', exist_ok=True)
makedirs('./assets/images/720', exist_ok=True)
makedirs('./assets/images/1080', exist_ok=True)
makedirs('./assets/images/review', exist_ok=True)
makedirs('./assets/images/small', exist_ok=True)
makedirs('./assets/images/find', exist_ok=True)
makedirs('./assets/images/find/720', exist_ok=True)
makedirs('./assets/images/find/1080', exist_ok=True)
makedirs('./assets/images/find/review', exist_ok=True)
makedirs('./assets/images/find/small', exist_ok=True)
# set the escape character for curly brace formatting
escapeCharacter = '\n'
# set the base url
baseURL = "https://www.classfind.com/trent/"
"""
# photoNames = [
# "bata102.jpg",
# "bata102.jpg",
# "bata103.jpg",
# "bata107.1.jpg",
# "bata107.2.jpg",
# "bata201.jpg",
# "bata210.jpg",
# "bata314.jpg",
# "bata401.jpg",
# "bata402.jpg",
# "bike5.jpg",
# "CCNG4.jpg",
# "CCNI1.jpg",
# "CCNI2.jpg",
# "CCNK1.jpg",
# "CCNM2.jpg",
# "CCS307.jpg",
# "CCWA1.jpg",
# "CCWA2.jpg",
# "CCWC3.jpg",
# "seasonedspoon4.jpg",
# "CSBD101.jpg",
# "CSBD109.jpg",
# "CSBD113.jpg",
# "CSBD116.jpg",
# "CSBE101.jpg",
# "CSBE103.jpg",
# "DNAD103.jpg",
# "DNAB104.jpg",
# "DNAB105.jpg",
# "DNAD105.jpg",
# "DNAD106.jpg",
# "DNAD108.jpg",
# "DNAB110.1.jpg",
# "DNAB110.2.jpg",
# "DNAB113.jpg",
# "DNAC141.jpg",
# "DNAC142.jpg",
# "DNAD202.jpg",
# "DNAD208.jpg",
# "DNAC215.jpg",
# "DNAC231.jpg",
# "DNAC231.jpg",
# "DNAC233.jpg",
# "ECC201.jpg",
# "ECC207.jpg",
# "ECC208.jpg",
# "ECC212.jpg",
# "ESCC111.3.jpg",
# "ESCA202.jpg",
# "ECC208.jpg",
# "ESCC202.jpg",
# "ESCB203.jpg",
# "ESCA205.jpg",
# "ESC209.jpg",
# "ESCB305.jpg",
# "enviroscience30.jpg",
# "ESCB319.jpg",
# "FPHL101.jpg",
# "GCS103-2.jpg",
# "GCS105-3.jpg",
# "GCS106-3.jpg",
# "GCS108-3.jpg",
# "GCS110-2.jpg",
# "GCS111-2.jpg",
# "GCS112-2.jpg",
# "GCS114.jpg",
# "GCS115-2.jpg",
# "FPHL117.jpg",
# "GCS345.jpg",
# "OCAW101.2.jpg",
# "OCA109.jpg",
# "OCA128.jpg",
# "OCA134.jpg",
# "OCA143.jpg",
# "OCA171.jpg",
# "OCA203.jpg",
# "OCA204.jpg",
# "OCA205.jpg",
# "OCA206.jpg",
# "OCA207.jpg",
# "OCA208.jpg",
# "OCA219.jpg",
# "SC103-2.jpg",
# "SC115.jpg",
# "SC137-2.jpg",
# "SCW1W2.jpg",
# "SC203.jpg",
# "SC208.jpg",
# "SC215.jpg",
# "SCW3W4.jpg",
# "SCW3W4.jpg",
# "SC305.jpg",
# "SC317.jpg",
# "CH102.jpg",
# "SC.jpg",
# "SC.jpg",
# "TC101.jpg",
# "WH.jpg",
# "WH.jpg",
# ]
# # Remove duplicates
# photoNames = list(set(photoNames))
# completedPhotos = []
# print(f'{len(photoNames) * 3} images to download')
# print(f'{round((len(completedPhotos)/(len(photoNames) * 3)), 4) * 100}% completed, {len(completedPhotos)} downloaded, downloading {str(None)} ', end='\r', flush=True)
# # Function to download an image
# def download_image(url, save_path):
# response = get(url)
# if response.status_code == 200:
# with open(save_path, 'wb') as file:
# file.write(response.content)
# # print(f'Downloaded: {save_path}')
# else:
# # print(f'Failed to download: {save_path}')
# pass
# if exists(save_path):
# completedPhotos.append(save_path)
# # Function to download images with different resolutions
# threads = []
# for photo_name in photoNames:
# resolutions = ['review', '720', '1080']
# for resolution in resolutions:
# url = f"{baseURL}{resolution}/{photo_name}"
# save_path = f"./assets/images/{resolution}/{photo_name}"
# print(f'{round((len(completedPhotos)/(len(photoNames) * 3)), 4) * 100}% completed, {len(completedPhotos)} downloaded, downloading {save_path} ', end='\r', flush=True)
# if not exists(save_path):
# download_image(url, save_path)
# # print("All downloads completed.")
"""
# initialize empty lists for photos to download and completed photos
photosToDownload = []
completedPhotos = []
# Function to download an image
def download_image(url, save_path):
"""Downloads an image from a url and saves it to a path
Args:
url (str): The url of the image to download
save_path (str): The path to save the image to
"""
# download the image
response = get(url)
# check if the image was downloaded
if response.status_code == 200:
# save the image by writing the response content to the file
with open(save_path, 'wb') as file:
file.write(response.content)
# if the image wasn't downloaded
else:
# don't save the image
pass
# check if the image exists
if exists(save_path):
# add the image to the list of completed photos
completedPhotos.append(save_path)
# # open the assetInfo file
# with open('assetInfo.txt', 'w') as assetInfoFile:
# # initialize the browser service
# chromeService = Service(
# '/usr/bin/chromedriver', )
# # set the browser service to not show a window when running to disable console spam and save resoucees to increase performance
# # chromeService.creation_flags = CREATE_NO_WINDOW
# # initialize the browser options
# chromeOptions = Options()
# """# set the browser options to not show a window when running to disable console spam and save resoucees to increase performance
# chromeOptions.add_argument('--headless')"""
# chromeOptions.add_argument('--log-level=3')
# # initialize the browser
# browser = Chrome(service=chromeService, options=chromeOptions)
# # initialize the browser action chain
# action = ActionChains(browser)
# # go to the base url
# browser.get(baseURL)
# # # wait for user to start script
# # input('Press Return To Continue...')
# sleep(10)
# # loop through all trent centers
# for trentCenterIndex in range(len(browser.find_elements(By.XPATH, "//div[@id='tab1']/div[@class='buttoncontainer']"))):
# # print the name of the trent center
# print(browser.find_elements(By.XPATH, "//div[@id='tab1']/div[@class='buttoncontainer']")[trentCenterIndex].find_element(
# By.XPATH, "div[2]").text)
# # write the name of the trent center to the assetInfo file
# assetInfoFile.write(
# f'''{browser.find_elements(By.XPATH, "//div[@id='tab1']/div[@class='buttoncontainer']")[trentCenterIndex].find_element(By.XPATH, "div[2]").text}\n''')
# # press ctrl + home and hold
# browser.find_elements(
# By.XPATH, "//body")[0].send_keys(Keys.CONTROL)
# # wait 0.1 seconds
# sleep(0.1)
# # release ctrl + home
# browser.find_elements(By.XPATH, "//body")[0].send_keys(Keys.HOME)
# # wait for the trent center to load
# sleep(10)
# # click on the trent center
# browser.find_elements(
# By.XPATH, "//div[@id='tab1']/div[@class='buttoncontainer']")[trentCenterIndex].click()
# # wait for the trent center to load
# while len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) == 0 and len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) == 0:
# # refresh the page
# browser.refresh()
# # wait for the trent center to load
# while len(browser.find_elements(By.XPATH, "//div[@id='tab1']/div[@class='buttoncontainer']")) == 0:
# # press ctrl + home and hold
# browser.find_elements(
# By.XPATH, "//body")[0].send_keys(Keys.CONTROL)
# # wait 0.1 seconds
# sleep(0.1)
# # release ctrl + home
# browser.find_elements(
# By.XPATH, "//body")[0].send_keys(Keys.HOME)
# # wait 10 seconds for the page to load
# sleep(10)
# # get all trent centers
# trentCenters = browser.find_elements(
# By.XPATH, "//div[@id='tab1']/div[@class='buttoncontainer']")
# # click on the trent center
# trentCenters[trentCenterIndex].click()
# # wait for the trent center to load
# sleep(10)
# # wait for the trent center to load
# while len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) == 0 and len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) == 0:
# # wait for the trent center to load
# sleep(10)
# # wait for the trent center to load
# sleep(10)
# # loop through all trent center floors
# for trentCenterFloorIndex in range(len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) if len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) != 0 and len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) == 0 else 1):
# waitForTrentCenterFloor = True
# # wait for the trent center to load
# while len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) == 0 and (len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) == 0 or len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) < trentCenterFloorIndex):
# # wait for the trent center to load
# sleep(10)
# else:
# if len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) != 0 and len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) == 0:
# trentCenterFloorIndex = 0
# waitForTrentCenterFloor = False
# if waitForTrentCenterFloor:
# # wait for the trent center to load
# sleep(10)
# # print the name of the trent center floor
# print(
# f''' - {browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")[trentCenterFloorIndex].find_element(By.XPATH, "div").text}''')
# # write the name of the trent center floor to the assetInfo file
# assetInfoFile.write(
# f''' - {browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")[trentCenterFloorIndex].find_element(By.XPATH, "div").text}\n''')
# # click on the trent center floor
# browser.find_elements(
# By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")[trentCenterFloorIndex].click()
# # wait for the trent center floor to load
# while len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) == 0:
# # wait for the trent center floor to load
# sleep(10)
# # wait for the trent center floor to load
# sleep(10)
# # loop through all trent center floor rooms
# for trentCenterFloorRoomIndex in range(len(browser.find_elements(By.XPATH, "//div[@class='roomholder']"))):
# # wait for the trent center floor to load
# while len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) == 0:
# # wait for the trent center floor to load
# sleep(10)
# # wait for the trent center floor to load
# sleep(10)
# # print the name of the trent center floor room
# print(
# f''' - {browser.find_elements(By.XPATH, "//div[@class='roomholder']")[trentCenterFloorRoomIndex].find_element(By.XPATH, "div[@class='roomtitle']").text}''')
# # write the name of the trent center floor room to the assetInfo file
# assetInfoFile.write(
# f''' - {browser.find_elements(By.XPATH, "//div[@class='roomholder']")[trentCenterFloorRoomIndex].find_element(By.XPATH, "div[@class='roomtitle']").text}\n''')
# # open a new window for the trent room find page and go to the trent room find page
# browser.execute_script(
# f'''window.open("{ browser.find_elements(By.XPATH, "//div[@class='roomholder']")[trentCenterFloorRoomIndex].find_element(By.XPATH, """div[@class='roomdirections']/a""").get_attribute("""href""")}");''')
# # switch to the new window
# browser.switch_to.window(browser.window_handles[1])
# # wait for the trent room find page to load
# while len(browser.find_elements(By.XPATH, "//ul[@id='steplist2']/li")) == 0 and len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div")) == 0:
# # wait for the trent room find page to load
# sleep(10)
# # wait for the trent room find page to load
# sleep(10)
# # print the number of steps
# print(f''' - {len(browser.find_elements(By.XPATH, "//ul[@id='steplist2']/li"))} Step{"" if len(browser.find_elements(By.XPATH, "//ul[@id='steplist2']/li")) == 1 else "s"}''' if len(browser.find_elements(
# By.XPATH, "//ul[@id='steplist2']/li")) != 0 else f''' - {len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div"))} Step{"" if len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div")) == 1 else "s"}''')
# # write the number of steps to the assetInfo file
# assetInfoFile.write(f''' - {len(browser.find_elements(By.XPATH, "//ul[@id='steplist2']/li"))} Step{"" if len(browser.find_elements(By.XPATH, "//ul[@id='steplist2']/li")) == 1 else "s"}{escapeCharacter}''' if len(browser.find_elements(
# By.XPATH, "//ul[@id='steplist2']/li")) != 0 else f''' - {len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div"))} Step{"" if len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div")) == 1 else "s"}{escapeCharacter}''')
# # iterate through all steps
# for trentCenterFloorRoomFindStepDescriptionIndex in range(len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div/div/div[@id='description']" if len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div/div/div[@id='description']")) != 0 else "//div[@id='layoutwithbackdrop']/div/section/div/div/div[@id='description']"))):
# # print the step number
# print(
# f' - Step {trentCenterFloorRoomFindStepDescriptionIndex + 1}')
# # write the step number to the assetInfo file
# assetInfoFile.write(
# f' - Step {trentCenterFloorRoomFindStepDescriptionIndex + 1}\n')
# # print the step description
# print(
# f''' - {browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div/div/div[@id='description']" if len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div/div/div[@id='description']")) != 0 else "//div[@id='layoutwithbackdrop']/div/section/div/div/div[@id='description']")[trentCenterFloorRoomFindStepDescriptionIndex].text.split(escapeCharacter)[0]}''')
# # write the step description to the assetInfo file
# assetInfoFile.write(
# f""" - {browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div/div/div[@id='description']" if len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div/div/div[@id='description']")) != 0 else "//div[@id='layoutwithbackdrop']/div/section/div/div/div[@id='description']")[trentCenterFloorRoomFindStepDescriptionIndex].text.split(escapeCharacter)[0]}{escapeCharacter}""")
# # get the photo src link
# photosToDownloadSrc = browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div/img" if len(browser.find_elements(By.XPATH, "//div[@id='layoutwithbackdrop']/section/div/img")) != 0 else "//div[@id='layoutwithbackdrop']/div/section/div/img")[
# trentCenterFloorRoomFindStepDescriptionIndex].get_attribute("src")
# # iterate through all resolutions
# for i in range(4):
# # change the resolution
# photosToDownloadSrcSplit = photosToDownloadSrc.split(
# "/")
# photosToDownloadSrcSplit[-2] = "review" if i == 0 else "small" if i == 1 else "720" if i == 2 else "1080"
# # check if the photo exists
# response = get("/".join(photosToDownloadSrcSplit))
# if response.status_code == 200:
# # add the photo to the list of photos to download
# photosToDownload.append(
# "/".join(photosToDownloadSrcSplit))
# # print the photo src link
# print(
# f" - {'/'.join(photosToDownloadSrcSplit)}")
# # write the photo src link to the assetInfo file
# assetInfoFile.write(
# f" - {'/'.join(photosToDownloadSrcSplit)}{escapeCharacter}")
# else:
# # don't add the photo to the list of photos to download
# pass
# # go back to the main page
# browser.close()
# # wait for the main page to load
# sleep(10)
# # switch to the main page
# browser.switch_to.window(browser.window_handles[0])
# # wait for the main page to load
# while len(browser.find_elements(By.XPATH, "//div[@id='tab1']/div[@class='buttoncontainer']")) == 0:
# # press ctrl + home and hold
# browser.find_elements(
# By.XPATH, "//body")[0].send_keys(Keys.CONTROL)
# # wait 0.1 seconds
# sleep(0.1)
# # release ctrl + home
# browser.find_elements(
# By.XPATH, "//body")[0].send_keys(Keys.HOME)
# # wait 10 seconds for the page to load
# sleep(10)
# waitForTrentCenterFloor = True
# # click on the trent center
# browser.find_elements(
# By.XPATH, "//div[@id='tab1']/div[@class='buttoncontainer']")[trentCenterIndex].click()
# # wait for the trent center to load
# while (len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) if len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) != 0 and len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) == 0 else 1) == 0:
# # wait 10 seconds for the page to load
# sleep(10)
# else:
# # if (len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) if len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) != 0 and len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) == 0 else 1) != 0:
# # load trent center rooms if no floors are found but rooms are found
# if len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) != 0 and len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) == 0:
# trentCenterFloorIndex = 0
# waitForTrentCenterFloor = False
# # if the trent center floor is found
# if waitForTrentCenterFloor:
# # click on the trent center floor
# browser.find_elements(
# By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")[trentCenterFloorIndex].click()
# # wait for the trent center floor to load
# while len(browser.find_elements(By.XPATH, "//div[@class='roomholder']")) == 0 and len(browser.find_elements(By.XPATH, "//table[@class='notablestyle floorfind growfloorleft']/tbody/tr/td[not(@class)]")) == 0:
# # wait 10 seconds for the page to load
# sleep(10)
# # close the browser
# browser.quit()
# # initialize the list of photos to download
# photosToDownload = []
# # write the photos to download to the assetInfo file
# with open('assetInfo.txt', 'r') as assetInfoFile:
# for line in assetInfoFile.readlines():
# if "https://" in line:
# # if not exists(f"./assets/images/find/{line.strip()[2:].split('/')[-2]}/{line.strip()[2:].split('/')[-1]}"):
# photosToDownload.append(line.strip()[2:].split('/')[-1])
# # read the photos to download from the assetUrlsInfo file
# with open('assetUrlsInfo.txt', 'r') as assetUrlsInfoFile:
# # iterate through all lines in the assetUrlsInfo file
# for line in assetUrlsInfoFile.readlines():
# # add the photo to download to the list of photos to download
# photosToDownload.append(line.strip())
# remove duplicates
photosToDownload = list(set(photosToDownload))
# print(photosToDownload)
# # print the number of photos to download and the number of photos downloaded
# print(f'{len(photosToDownload)} images to download')
# print(f'{round((len(completedPhotos)/len(photosToDownload)), 4) * 100}% completed, {len(completedPhotos)} downloaded, downloading {str(None)} ', end='\r', flush=True)
# # # input('Press Return To Continue...')
# # write the photos to download to the assetInfoUrls file with the photos to download asset uris for flutter
# with open('assetInfoUrls.txt', 'w') as assetInfoUrlsFile:
# # download the photos
# for photoToDownloadIndex in range(len(photosToDownload)):
# assetInfoUrlsFile.write(
# f"{photosToDownload[photoToDownloadIndex]}{escapeCharacter}")
# # get the photo url
# url = photosToDownload[photoToDownloadIndex]
# # get the photo save path
# save_path = f"./assets/images/find/{url.split('/')[-2]}/{url.split('/')[-1]}"
# assetInfoUrlsFile.write(f"{save_path}{escapeCharacter}")
# # print the number of photos to download and the number of photos downloaded
# print(f'{round((len(completedPhotos)/len(photosToDownload)), 4) * 100}% completed, {len(completedPhotos)} downloaded, downloading {save_path} ', end='\r', flush=True)
# # download the photo if it doesn't exist
# if not exists(save_path):
# # download the photo
# download_image(url, save_path)
def returnNextBraceIndex(varFileLinesIndex: int):
while variablesFileLines[varFileLinesIndex].strip() != "),":
varFileLinesIndex += 1
return varFileLinesIndex
variablesFileLines = []
variablesFileLinesToWrite = []
with open('./lib/universals/variables.dart', 'r') as variablesFile:
variablesFileLines = variablesFile.readlines()
with open('assetInfo.txt', 'r') as assetInfoFile:
linesToSkip = []
lines = assetInfoFile.readlines()
fin = False
for varFileLine in variablesFileLines:
if fin:
variablesFileLinesToWrite.append("),\n")
variablesFileLinesToWrite.append("],\n")
variablesFileLinesToWrite.append("),\n")
variablesFileLinesToWrite.append("\n\n")
fin = False
variablesFileLinesToWrite.append(varFileLine)
if "roomNumber:" in varFileLine:
for line in lines:
if len(line.strip()) == len(line):
continue
if line in linesToSkip:
linesToSkip.remove(line)
continue
if line[4] == "-" and varFileLine.strip().replace("roomNumber: ", "").replace(",", "").replace("'", "").strip() == line[6:].split(' ')[1].strip():
for deepLine in lines[lines.index(line) + 1:]:
if deepLine[4] == "-":
break
linesToSkip.append(deepLine)
# if deepLine[7] == "-":
# if lines.index(deepLine) > 3:
# variablesFileLinesToWrite.append("),\n")
# variablesFileLinesToWrite.append("],\n")
# variablesFileLinesToWrite.append("),\n")
# variablesFileLinesToWrite.append("\n\n")
if deepLine[9] == "-":
if lines.index(deepLine) > 3:
if deepLine[-3:].strip() != "1":
variablesFileLinesToWrite.append(
"),\n")
if deepLine[-3:].strip() == "1":
variablesFileLinesToWrite.append(
"findRoomSteps: TrentRoomFindSteps(\n")
variablesFileLinesToWrite.append(
"steps: <TrentRoomFindStep?>[\n")
variablesFileLinesToWrite.append(
"TrentRoomFindStep(\n")
variablesFileLinesToWrite.append(
f"stepNumber: '{deepLine[-3:].strip()}',\n")
deepLine = deepLine.replace("\n", "")
if len(deepLine) >= 20 and deepLine[12] == "-" and deepLine[14:46] != "https://www.classfind.com/trent/" and deepLine[14:35] != "./assets/images/find/":
fin = True
variablesFileLinesToWrite.append(
f"stepDescription: '{deepLine[14:]}',\n")
if len(deepLine) >= 20 and deepLine[12] == "-" and deepLine[14:46] == "https://www.classfind.com/trent/" and deepLine[14:35] != "./assets/images/find/":
continue
if len(deepLine) >= 20 and deepLine[12] == "-" and deepLine[14:46] != "https://www.classfind.com/trent/" and deepLine[14:41] == "./assets/images/find/small/":
variablesFileLinesToWrite.append(
f"stepSmallImageAssetPath: '{deepLine[16:]}',\n")
if len(deepLine) >= 20 and deepLine[12] == "-" and deepLine[14:46] != "https://www.classfind.com/trent/" and deepLine[14:39] == "./assets/images/find/720/":
variablesFileLinesToWrite.append(
f"stepHDImageAssetPath: '{deepLine[16:]}',\n")
if len(deepLine) >= 20 and deepLine[12] == "-" and deepLine[14:46] != "https://www.classfind.com/trent/" and deepLine[14:40] == "./assets/images/find/1080/":
variablesFileLinesToWrite.append(
f"stepFHDImageAssetPath: '{deepLine[16:]}',\n")
break
with open('./lib/universals/variable.dart', 'w') as variableFile:
for deepLine in variablesFileLinesToWrite:
variableFile.write(deepLine)