This notebook copies sound files (recordings) into the pumilio directory structure based on a csv file containing information about the time and location of recording.
csv_filepath – path to a csv file containing information about the time and location of each recording
sound_directory – path to the directory that will contain the recordings
source_directory – path to the directory containing the unorganized recordings
In [2]:
csv_filepath = ""
In [3]:
sound_directory = ""
In [102]:
source_directory = os.path.dirname(os.path.dirname(working_directory))
In [97]:
import pandas
import os.path
from datetime import datetime
import subprocess
In [98]:
visits = pandas.read_csv(csv_filepath)
In [99]:
visits = visits.sort_values(by=['Time'])
In [110]:
visits['ID'] = visits['ID'].map('{:g}'.format)
In [111]:
sites = visits['ID'].drop_duplicates().dropna().as_matrix()
In [108]:
for site in sites:
path = os.path.join(working_directory, str(site))
if os.path.exists(path):
os.rmdir(path)
os.mkdir(path)
In [113]:
for index, visit in visits.iterrows():
try:
dt = datetime.strptime(visit['Time'], '%Y-%m-%d %X')
except TypeError:
print('Time was not a string, but had a value of: "{0}"'.format(visit['Time']))
continue
source_file = os.path.join(source_directory, dt.strftime('%Y-%m-%d'), 'converted', '{0}.flac'.format(dt.strftime('%y%m%d-%H%M%S')))
destination_file = os.path.join(working_directory, str(visit['ID']), '{0}.flac'.format(dt.strftime('%y%m%d-%H%M%S')))
if os.path.exists(source_file):
subprocess.check_output(["cp", source_file, destination_file])
print('copying {0}'.format(dt.strftime('%y%m%d-%H%M%S')))
else:
print('\n')
print('{0} does not exist!'.format(dt.strftime('%y%m%d-%H%M%S')))
print(visit['Name'])
print('\n')
print('\n')
print('done')