Post Metadata Writer
This program takes the table from post_csv_writer and adds the post information to the posts' metadata. It then moves the files to a final directory for upload or storage.
Python (with os, re, csv, and shutil modules)
# NOTE This program must use a CSV from the "post_csv_writer" program regarding the location of the post data and the character substitutions.
import os
import re
import csv
import shutil
final_dest = "#DIRECTORY TO PUT PHOTOS ONCE THEY ARE UPDATED WITH THE METADATA#"
base = "#DIRECTORY OF THE BASE FACEBOOK FOLDER ON MACHINE#"
# Use the CSV file written by the "post_csv_writer" program.
filename = "#LOCATION OF THE CSV FILE TO READ#"
# Initializes some variables.
photo_count = 0
# Opens the CSV and iterates through each row, saving the proper metadata to the file and moving it to the final_dest directory.
with open(filename, mode='r') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
col_count = 0
for col in row:
col_count += 1
if col_count == 1:
# First column in the CSV is the file's path.
full_path = col
if col_count == 2:
# Second column in the CSV is the file's description.
description = col
if col_count == 3:
# Third column in the CSV is the file's date.
date = col
# Makes sure no videos were saved to the csv to prevent errors.
if "/videos/" not in full_path and full_path != " " and os.path.isfile(full_path):
photo_count += 1
# Makes common character replacements to prevent errors
description = description.replace("`", ",")
description = description.replace("\\n", "\n")
description = description.replace("\"", "”")
description = description.replace("\'", "’")
description = description.replace("-", "—")
bashCommand = "Exiftool \"-datetimeoriginal=" + date + "\" \"-CreateDate=" + date + "\" \"-ModifyDate=" + date + "\" \"-filemodifydate=" + date + "\" -IPTC:Caption-Abstract=\'" + description + "\' -xmp:description=\'" + description + "\' -overwrite_original " + full_path
print('\x1b[6;30;42m' + "ADDING METADATA - " + date + " - " + description + '\x1b[0m')
os.system(bashCommand)
shutil.move(full_path, final_dest)
# Prints the program's post count
print("Edited " + photo_count + " posts' metadata!")