This repository has been archived by the owner on May 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4824ad
commit aa41335
Showing
8 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
# tempest-rename | ||
# Tempest Rename | ||
|
||
Simple Python application to rename student photographs from their admission number to their forename and surname based on report generated by SIMS. | ||
|
||
## How to | ||
|
||
1. Export the student SIMS report into a CSV with the following columns forename, surname, adno | ||
2. Save the report as 'data.csv' into this root of this application overriding the example file - ensure the csv contains the leading '00'. | ||
3. Place the Tempest photographs into the folder 'Photographs to Rename', these should be named with the student adno. | ||
|
||
Run the main.py script and the matched files will be renamed. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
forename,surname,adno | ||
Jane,Smith,00147357 | ||
John,Jones,00198154 | ||
Jessica,Gilmore,00567128 | ||
Josh,Bramble,00741685 | ||
Josephine,Warren,00996342 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os, csv | ||
|
||
def main(): | ||
directory_path = os.getcwd() + '/' | ||
print('My current directory is: ' + directory_path) | ||
|
||
## import photo directory into listdir | ||
path = directory_path + 'Photographs to Rename' | ||
file_extension = '.bmp' | ||
items = os.listdir(path) | ||
|
||
|
||
## csv handling | ||
csv_open = open(directory_path+'data.csv','r') | ||
csv_read = csv.reader(csv_open, delimiter=',') | ||
next(csv_read) ## skip the first row. | ||
|
||
## initialise an empty list | ||
photographs = [] | ||
|
||
|
||
## photograph loop | ||
for item in items: | ||
## clean up file names | ||
clean_item = (item.strip(file_extension)) | ||
## add clean file name into photograph list | ||
photographs.append(clean_item) | ||
|
||
## nested for loop, reads the records from csv file with photograph list, looking for a match | ||
for record in csv_read: | ||
for photograph in photographs: | ||
## record[2] is the adno column | ||
if record[2] == photograph: | ||
## rename files if they match | ||
os.rename(path+'/'+photograph+file_extension,path+'/'+record[0]+' '+record[1]+file_extension) | ||
|
||
|
||
csv_open.close() #close csv when finished. | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.