Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Livingdead1989 committed May 27, 2021
1 parent c4824ad commit aa41335
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
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.

6 changes: 6 additions & 0 deletions data.csv
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
42 changes: 42 additions & 0 deletions main.py
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 added sample photos/00147357.bmp
Binary file not shown.
Binary file added sample photos/00198154.bmp
Binary file not shown.
Binary file added sample photos/00567128.bmp
Binary file not shown.
Binary file added sample photos/00741685.bmp
Binary file not shown.
Binary file added sample photos/00996342.bmp
Binary file not shown.

0 comments on commit aa41335

Please sign in to comment.