|
import os |
|
|
|
|
|
input_dir = 'data/top_3_images' |
|
output_dir = 'data/output_generated_file' |
|
|
|
|
|
if not os.path.exists(output_dir): |
|
os.makedirs(output_dir) |
|
|
|
|
|
for filename in os.listdir(input_dir): |
|
if filename.endswith('.txt'): |
|
file_path = os.path.join(input_dir, filename) |
|
|
|
|
|
with open(file_path, 'r') as file: |
|
file_content = file.read() |
|
|
|
|
|
is_product = 'product' in filename.lower() |
|
if is_product: |
|
branding_file = os.path.join(output_dir, 'Product_branding.txt') |
|
content_marketing_file = os.path.join(output_dir, 'Product_content_marketing.txt') |
|
smm_file = os.path.join(output_dir, 'Product_smm.txt') |
|
else: |
|
branding_file = os.path.join(output_dir, 'Competitor_branding.txt') |
|
content_marketing_file = os.path.join(output_dir, 'Competitor_content_marketing.txt') |
|
smm_file = os.path.join(output_dir, 'Competitor_smm.txt') |
|
|
|
|
|
lines = file_content.split('\n') |
|
|
|
|
|
branding_content = [] |
|
content_marketing_content = [] |
|
smm_content = [] |
|
|
|
current_category = None |
|
|
|
|
|
for line in lines: |
|
if "Branding" in line: |
|
current_category = 'Branding' |
|
elif "Content Marketing" in line: |
|
current_category = 'Content Marketing' |
|
elif "Social Media Marketing" in line: |
|
current_category = 'Social Media Marketing' |
|
|
|
|
|
if current_category == 'Branding': |
|
branding_content.append(line) |
|
elif current_category == 'Content Marketing': |
|
content_marketing_content.append(line) |
|
elif current_category == 'Social Media Marketing': |
|
smm_content.append(line) |
|
|
|
|
|
with open(branding_file, 'w') as bf: |
|
bf.write('\n'.join(branding_content) + '\n\n') |
|
|
|
with open(content_marketing_file, 'w') as cmf: |
|
cmf.write('\n'.join(content_marketing_content) + '\n\n') |
|
|
|
with open(smm_file, 'w') as smf: |
|
smf.write('\n'.join(smm_content) + '\n\n') |
|
|
|
print(f"Processed {filename} and saved data into {branding_file}, {content_marketing_file}, and {smm_file}") |
|
|