-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventory_script.py
562 lines (497 loc) · 18 KB
/
inventory_script.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
import os
import csv
# Asking the user questions to decide the workflow that is going to be used by the script
proj_number = input("What is the project number? ")
def ask_projnum_again():
proj_number = input("What is the project number? ")
if proj_number.startswith("p") or proj_number.startswith("j"):
proj_number_leng = len(proj_number)
if proj_number_leng != 5:
print("Please answer with a 4 digit number after 'p'")
ask_projnum_again()
else:
print()
else:
print("Please answer with the number prefixed by a p")
ask_projnum_again()
if proj_number.startswith("p") or proj_number.startswith("j"):
proj_number_leng = len(proj_number)
if proj_number_leng != 5:
print("Please answer with a 4 digit number after 'p' or 'j'")
ask_projnum_again()
else:
print()
else:
print("Please answer with the number prefixed by a p or j")
ask_projnum_again()
proj_4dig = input("What is the four letter id? ")
def proj_name_check_again():
proj_4dig = input("What is the four letter id? ")
proj_name_leng = len(proj_4dig)
if proj_name_leng != 4:
print("Please answer again with a four letter name")
proj_name_check_again()
else:
print("Has correct number of letters - cleared to continue")
proj_name_leng = len(proj_4dig)
if proj_name_leng != 4:
print("Please answer again with a four letter name")
proj_name_check_again()
else:
print()
box_other = input("Are there boxes and folders? y for Yes and n for No ")
# Building some of the intial variables that will be used
field_names = [
"Spreadsheet Row Number",
"work_image",
"structure",
"role",
"work_type",
"work_accession_number",
"file_accession_number",
"filename",
"label",
"description",
"Capture date",
"Staff Initials",
"Container number ex. Box Number",
"folder number",
"Width (cm.)",
"Height (cm.)",
"Date (Year+Month+Day)",
"project_job_number",
"Notes about album page or photo",
"Production Notes",
"Creator",
"Source",
"Copyright Notice",
]
file_path = input("Where do you want to save to? ")
csv_name = (
proj_number + "_" + proj_4dig + "_" + "inventory" + ".csv"
) # assigning the CSV file a name based on the data that the user input
open_CSV = (
'"' + "start EXCEL.exe" + " " + csv_name + '"'
) # Part of the command to open the CSV file in Excel -- you can swap ' EXCEL.exe' for your preferred CSV editor that is installed on your PC
# defining functions
def ask_overwrite():
overwrite = input(
"File already exists, do you want to append? y for yes and n for no -- will terminate script"
)
if overwrite == "y":
with open(os.path.join(file_path, open_CSV), "w") as fp:
fp.write()
elif overwrite == "n":
print("Try running the script again")
def save_CSV():
try:
pass
except:
pass
def ask_new_work_bOrf():
new_work = input(
"Do you want to add a new work - y for yes, n for no which will open the CSV "
)
if new_work == "y": # if you want a new work this will run
file_number = 1
work_info = input("What is the work info? ")
number_files = int(input("How many works? ")) # number to loop by
while (
file_number <= number_files
): # runs while the file number is less than or equal to the number of files that you need
# Leading Zeros
file_number = str(file_number).zfill(4)
# Leading Zeros
# Combines the information that the user has put in to fill out select fields in the CSV file
inventory = [
{
"work_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ work_info,
"file_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ work_info
+ "_"
+ file_number
+ "_"
+ "a",
"filename": proj_number
+ "_"
+ proj_4dig
+ "_"
+ work_info
+ "_"
+ file_number
+ "_"
+ "a"
+ ".tif",
"role": "A",
"work_type": "IMAGE",
"project_job_number": proj_number,
}
]
for data in inventory:
writer.writerows(inventory)
# Below increments the row and file up by one
file_number = int(file_number) + 1
ask_new_work_bOrf()
elif new_work == "n":
save_CSV() # command to save the CSV
os.system(open_CSV) # Command to open the CSV in Excel
def ask_new_work_choose():
new_work = input(
"Do you want to add a new work - y for yes, n for no which will open the CSV "
)
if new_work == "y": # if you want a new work this will run
file_number = 1
work_info = input("What is the work info? ")
number_files = int(input("How many works? ")) # number to loop by
while (
file_number <= number_files
): # runs while the file number is less than or equal to the number of files that you need
# Leading Zeros
file_number = str(file_number).zfill(4)
# Leading Zeros
# Combines the information that the user has put in to fill out select fields in the CSV file
inventory = [
{
"work_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ work_info,
"file_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ work_info
+ "_"
+ file_number
+ "_"
+ "a",
"filename": proj_number
+ "_"
+ proj_4dig
+ "_"
+ work_info
+ "_"
+ file_number
+ "_"
+ "a"
+ ".tif",
"role": "A",
"work_type": "IMAGE",
"project_job_number": proj_number,
}
]
for data in inventory:
writer.writerows(inventory)
# Below increments the row and file up by one
file_number = int(file_number) + 1
ask_new_work_choose()
elif new_work == "n":
save_CSV() # Saves the CSV File
os.system(open_CSV) # Opens the CSV file in Excel
def ask_new_bOrf(): # function that will ask if you want to add a box or folder. If you want to add pages, answer 'n' to the question and then 'y' to the following question
new_bOrf = input(
"Do you want to add a work - y for yes, n for no (which will ask about if you want to add a work with page designation) "
)
if new_bOrf == "y": # if you want a new box or folder this will run
file_number = 1
box_number = input("What is the box number?")
folder_number = input("What is the folder number?")
# Leading Zeros
box_number = str(box_number).zfill(3)
folder_number = str(folder_number).zfill(2)
# Leading Zeros
folder_files = int(input("How many works? ")) # number to loop by
while (
file_number <= folder_files
): # runs while the file number is less than or equal to the number of files that you need
# Leading Zeros
file_number = str(file_number).zfill(2)
# Leading Zeros
inventory = [
{
"work_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ "b"
+ box_number
+ "_"
+ "f"
+ folder_number
+ "_"
+ file_number,
"file_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ "b"
+ box_number
+ "_"
+ "f"
+ folder_number
+ "_"
+ file_number
+ "_"
+ "0001"
+ "_"
+ "a",
"filename": proj_number
+ "_"
+ proj_4dig
+ "_"
+ "b"
+ box_number
+ "_"
+ "f"
+ folder_number
+ "_"
+ file_number
+ "_"
+ "0001"
+ "_"
+ "a"
+ ".tif",
"role": "A",
"work_type": "IMAGE",
"project_job_number": proj_number,
"Container number ex. Box Number": box_number,
"folder number": folder_number,
}
]
for data in inventory:
writer.writerows(inventory)
file_number = int(file_number) + 1
ask_new_bOrf()
elif new_bOrf == "n": # if you do not want to run a new box or folder
new_pages = input(
"Do you want to add a work with more than one page - y for Yes and n for No "
) # will ask if you want to add a work that has to have page designation
if new_pages == "y": # if you want to use page designation this will run
page_path()
elif new_pages == "n":
save_CSV() # Saves the CSV
os.system(open_CSV) # Opens the CSV in Excel
def page_path(): # This script runs when you want to add works with page designations
page_number = 1
box_number = input("What is the box number? ")
folder_number = input("What is the folder number? ")
# Leading Zeros
box_number = str(box_number).zfill(3)
folder_number = str(folder_number).zfill(2)
# Leading Zeros
file = input("What is your work number? ")
pages = int(
input("What is the number of images in the work? ")
) # number to loop by
while (
page_number <= pages
): # runs while the file number is less than or equal to the number of files that you need
# Leading Zeros
page_number = str(page_number).zfill(4)
file = str(file).zfill(2)
# Leading Zeros
inventory = [
{
"work_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ "b"
+ box_number
+ "_"
+ "f"
+ folder_number
+ "_"
+ file,
"file_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ "b"
+ box_number
+ "_"
+ "f"
+ folder_number
+ "_"
+ file
+ "_"
+ page_number
+ "_"
+ "a",
"filename": proj_number
+ "_"
+ proj_4dig
+ "_"
+ "b"
+ box_number
+ "_"
+ "f"
+ folder_number
+ "_"
+ file
+ "_"
+ page_number
+ "_"
+ "a"
+ ".tif",
"Container number ex. Box Number": box_number,
"folder number": folder_number,
"role": "A",
"work_type": "IMAGE",
"project_job_number": proj_number,
}
]
for data in inventory:
writer.writerows(inventory)
page_number = int(page_number) + 1
ask_new_bOrf() # will then call the ask_new_bOrf function to see if you want to add a box or folder next. If you want to run another work with page designations, answer 'n' to the first question and the 'y' to the next
# setting variables up to be used
page_number = 1
file_number = 1
new_bOrf = 0
if box_other == "y": # will run box folder version
pages_yn = input(
"Does your folder have a work with multiple images? (ex. a 3 page letter) y for Yes and n for No "
)
if pages_yn == "y": # runs if you need to designate page numbers
with open(csv_name, "a", newline="", encoding="utf-8") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=field_names)
writer.writeheader()
page_path()
elif pages_yn == "n":
box_number = input("What is the box number? ")
folder_number = input("What is the folder number? ")
# Leading Zeros
box_number = str(box_number).zfill(3)
folder_number = str(folder_number).zfill(2)
# Leading Zeros
folder_files = int(
input("What is the number of works? ")
) # number to loop by
with open(csv_name, "a", newline="", encoding="utf-8") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=field_names)
writer.writeheader()
while (
file_number <= folder_files
): # runs while the file number is less than or equal to the number of files that you need
# Leading Zeros
file_number = str(file_number).zfill(2)
# Leading Zeros
inventory = [
{
"work_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ "b"
+ box_number
+ "_"
+ "f"
+ folder_number
+ "_"
+ file_number,
"file_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ "b"
+ box_number
+ "_"
+ "f"
+ folder_number
+ "_"
+ file_number
+ "_"
+ "0001"
+ "_"
+ "a",
"filename": proj_number
+ "_"
+ proj_4dig
+ "_"
+ "b"
+ box_number
+ "_"
+ "f"
+ folder_number
+ "_"
+ file_number
+ "_"
+ "0001"
+ "_"
+ "a"
+ ".tif",
"Container number ex. Box Number": box_number,
"folder number": folder_number,
"role": "A",
"work_type": "IMAGE",
"project_job_number": proj_number,
}
]
for data in inventory:
writer.writerows(inventory)
# Below increments the file up by one
file_number = int(file_number) + 1
ask_new_bOrf()
elif box_other == "n": # will run choose your own adventure
work_info = input(
"What is your work info ex. v for volume? "
) # takes the place of the Box and Folder # information
number_files = int(
input("What is the number of images? ")
) # number to loop by
with open(csv_name, "a", newline="", encoding="utf-8") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=field_names)
writer.writeheader()
while (
file_number <= number_files
): # runs while the file number is less than or equal to the number of files that you need
# leading zeros
file_number = str(file_number).zfill(4)
# leading zeros
inventory = [
{
"work_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ work_info,
"file_accession_number": proj_number
+ "_"
+ proj_4dig
+ "_"
+ work_info
+ "_"
+ file_number
+ "_"
+ "a",
"filename": proj_number
+ "_"
+ proj_4dig
+ "_"
+ work_info
+ "_"
+ file_number
+ "_"
+ "a"
+ ".tif",
"role": "A",
"work_type": "IMAGE",
"project_job_number": proj_number,
}
]
for data in inventory:
writer.writerows(inventory)
# Below increments the row and file up by one
file_number = int(file_number) + 1
ask_new_work_choose()
else:
print("Try again running the script again with y for YES or n for NO")