| import os |
| import csv |
| import tarfile |
| import glob |
|
|
|
|
| version = '1' |
| platforms = {'twitter'} |
| |
|
|
| def upstream(version, platform): |
| raw_audio_path = f'./audio_raw/{platform}' |
| export_audio_path = f'./audio/{platform}' |
| raw_audio_files = glob.glob(f'{raw_audio_path}/*') |
| |
| raw_transcript_path = f'./transcript_raw/{platform}' |
| export_transcript_path = f'./transcript/{platform}' |
| raw_transcript_files = glob.glob(f'{raw_transcript_path}/*.csv') |
|
|
| |
| with tarfile.open(f'{export_audio_path}/{platform}_{version}.tar', 'w') as tar: |
| for file_path in raw_audio_files: |
| audio_paths = glob.glob(f'{file_path}/*.mp3') |
| folder_name = file_path.replace(raw_audio_path, '').replace('\\', '') |
| |
| for audio_path in [os.path.basename(f) for f in audio_paths]: |
| tar.add(name=f'{file_path}/{audio_path}', arcname=f'{folder_name}_{audio_path}') |
| |
| |
| transcripts = [] |
| for csv_path in raw_transcript_files: |
| transcript_id = csv_path.replace(raw_transcript_path, '').replace('\\', '').replace('.csv', '') |
| |
| with open(csv_path, 'rt', newline='', encoding="utf-8") as csvfile: |
| reader = csv.DictReader(csvfile) |
| raw_transcripts = [row for row in reader] |
| for raw_transcript in raw_transcripts: |
| raw_path = raw_transcript['path'] |
| audio_path = f'{transcript_id}_{raw_path}' |
| transcript = { |
| 'path': audio_path, |
| 'sentence': raw_transcript['sentence'] |
| } |
| transcripts.append(transcript) |
| |
| with open(f'{export_transcript_path}/{platform}_{version}.csv', 'wt', newline='', encoding="utf-8") as csvfile: |
| fieldnames = ['path', 'sentence'] |
| writer = csv.DictWriter(csvfile, fieldnames=fieldnames) |
| writer.writeheader() |
| writer.writerows(transcripts) |
| |
| return |
|
|
|
|
| |
| for platform in platforms: |
| upstream(version, platform) |