Skip to content

Commit

Permalink
Merge pull request #24 from nulib:Sophia_Inventory
Browse files Browse the repository at this point in the history
Lots of little updates. Now the script has a functional loop function that will write to a CSV
  • Loading branch information
SoFrans authored Feb 3, 2023
2 parents 8c227a7 + 257b4d9 commit 99f4717
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 33 deletions.
36 changes: 36 additions & 0 deletions Image/Inventory/CSVwriting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import csv
import os


proj_number=input("What is the project number?")
proj_4dig=input("What is the four letter id?")
box_other=input('Are there boxes and folders?')
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']


box_number=input("What is the box number?")
folder_number=input("What is the folder number?")
folder_files=int(input("How many files?")) #number to loop by
file_number=1
row_number=1


with open ('inventory.csv','a') as csvfile:
writer=csv.DictWriter(csvfile,fieldnames=field_names)
writer.writeheader()
while file_number <= folder_files:
file_number=str(file_number)
inventory=[{'Spreadsheet Row Number':row_number,'work_accession_number': proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number, 'file_accession_number':proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number+'_'+file_number+'_'+'01'+'_'+'a', 'filename': proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number+'_'+file_number+'_'+'01'+'_'+'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)


file_number=int(file_number)+1
row_number=row_number+1





os.system("start EXCEL.exe inventory.csv")
11 changes: 11 additions & 0 deletions Image/Inventory/inventory.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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
1,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_1_01_a,p0386_grea_b1_f1_1_01_a.tif,,,,,1,1,,,,p0386,,,,,
2,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_2_01_a,p0386_grea_b1_f1_2_01_a.tif,,,,,1,1,,,,p0386,,,,,
3,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_3_01_a,p0386_grea_b1_f1_3_01_a.tif,,,,,1,1,,,,p0386,,,,,
4,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_4_01_a,p0386_grea_b1_f1_4_01_a.tif,,,,,1,1,,,,p0386,,,,,
5,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_5_01_a,p0386_grea_b1_f1_5_01_a.tif,,,,,1,1,,,,p0386,,,,,
6,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_6_01_a,p0386_grea_b1_f1_6_01_a.tif,,,,,1,1,,,,p0386,,,,,
7,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_7_01_a,p0386_grea_b1_f1_7_01_a.tif,,,,,1,1,,,,p0386,,,,,
8,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_8_01_a,p0386_grea_b1_f1_8_01_a.tif,,,,,1,1,,,,p0386,,,,,
9,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_9_01_a,p0386_grea_b1_f1_9_01_a.tif,,,,,1,1,,,,p0386,,,,,
10,,,A,IMAGE,p0386_grea_b1_f1,p0386_grea_b1_f1_10_01_a,p0386_grea_b1_f1_10_01_a.tif,,,,,1,1,,,,p0386,,,,,
Expand Down
72 changes: 39 additions & 33 deletions Image/Inventory/inventory_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,52 @@

proj_number=input("What is the project number?")
proj_4dig=input("What is the four letter id?")
box_other=input('Are there boxes and folders?')
box_other=input('Are there boxes and folders? Y for Yes and N for No')
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']
row_number=1
file_number=1

# Whether or not there are box and folders
if box_other('YES'): # will run box folder version
folder_number=input("What is the folder number?")
if box_other=='Y': # will run box folder version
box_number=input("What is the box number?")
number_files=int(input("How many files?")) #number to loop by
row_number=int(0)
file_number=int(0)
for x in number_files():
file_number=file_number+1
row_number=row_number+1
if x!=number_files:
inventory=[{'Spreadsheet Row Number':row_number,'work_accession_number': proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number, 'file_accession_number':proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number+'_'+file_number+'_'+'01'+'_'+'a', 'filename': proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number+'_'+file_number+'_'+'01'+'_'+'a'+'.tif', 'Container number ex. Box Number':box_number, 'folder number':folder_number, 'role':'A', 'project_job_number':proj_number},]
else:
inventory=[{'Spreadsheet Row Number':row_number,'work_accession_number': proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number, 'file_accession_number':proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number+'_'+file_number+'_'+'01'+'_'+'a', 'filename': proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number+'_'+file_number+'_'+'01'+'_'+'a'+'.tif', 'Container number ex. Box Number': box_number, 'folder number':folder_number, 'role':'A', 'project_job_number':proj_number}]
with open('inventory.csv', 'w') as csvfile:
writer=csv.DictWriter(csv,fieldnames = field_names)
writer.writeheader()
writer.writerows(inventory)



elif box_other('NO'): #will run choose your own adventure
folder_number=input("What is the folder number?")
folder_files=int(input("How many files?")) #number to loop by

with open ('inventory.csv','a') 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
file_number=str(file_number)
inventory=[{'Spreadsheet Row Number':row_number,'work_accession_number': proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number, 'file_accession_number':proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number+'_'+file_number+'_'+'01'+'_'+'a', 'filename': proj_number+'_'+proj_4dig+'_'+'b'+box_number+'_'+'f'+folder_number+'_'+file_number+'_'+'01'+'_'+'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 row and file up by one
file_number=int(file_number)+1
row_number=row_number+1


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=input("How many files?") # number to loop by

for x in number_files():
file_number=file_number+1
row_number=row_number+1
if x!=number_files:
inventory=[{'Spreadsheet Row Number':row_number,'work_accession_number': proj_number+'_'+proj_4dig+'_'+work_info, 'file_accession_number':proj_number+'_'+proj_4dig+'_'+work_info+'_'+file_number+'_'+'01'+'_'+'a', 'filename': proj_number+'_'+proj_4dig+'_'+work_info+'_'+file_number+'_'+'01'+'_'+'a'+'.tif', 'Container number ex. Box Number':'N/A', 'folder number':'N/A', 'role':'A', 'project_job_number':proj_number},]
else:
inventory=[{'Spreadsheet Row Number':row_number,'work_accession_number': proj_number+'_'+proj_4dig+'_'+work_info, 'file_accession_number':proj_number+'_'+proj_4dig+'_'+work_info+'_'+file_number+'_'+'01'+'_'+'a', 'filename': proj_number+'_'+proj_4dig+'_'+work_info+'_'+file_number+'_'+'01'+'_'+'a'+'.tif', 'Container number ex. Box Number':'N/A', 'folder number':'N/A', 'role':'A', 'project_job_number':proj_number}]
with open('inventory.csv', 'w') as csvfile:
writer=csv.DictWriter(csv,fieldnames = field_names)
writer.writeheader()
writer.writerows(inventory)

with open ('inventory.csv','a') 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
inventory=[{'Spreadsheet Row Number':row_number,'work_accession_number': proj_number+'_'+proj_4dig+'_'+work_info, 'file_accession_number':proj_number+'_'+proj_4dig+'_'+work_info+'_'+file_number+'_'+'01'+'_'+'a', 'filename': proj_number+'_'+proj_4dig+'_'+work_info+'_'+file_number+'_'+'01'+'_'+'a'+'.tif', 'Container number ex. Box Number':'N/A', 'folder number':'N/A', '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
row_number=row_number+1


else:
print("Try again with YES or NO")
print("Try again with Y for YES or N for NO")

0 comments on commit 99f4717

Please sign in to comment.