Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement - #8

Open
johndpope opened this issue Aug 7, 2024 · 0 comments
Open

enhancement - #8

johndpope opened this issue Aug 7, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@johndpope
Copy link

make it able to take the exported account conversations.json -( from account > export data) and get all the conv uuid - and then download in bulk

import json
import os
import sys

def extract_attachments(data):
    for conversation in data:
        conversation_name = conversation['name']
        conversation_dir = f"extracted_{conversation['uuid']}"
        os.makedirs(conversation_dir, exist_ok=True)

        for message in conversation['chat_messages']:
            for attachment in message.get('attachments', []):
                file_name = attachment['file_name']
                content = attachment.get('extracted_content', '')
                
                if content:
                    file_path = os.path.join(conversation_dir, file_name)
                    with open(file_path, 'w', encoding='utf-8') as f:
                        f.write(content)
                    print(f"Extracted: {file_path}")

def main():

    json_file = 'conversations.json'

    try:
        with open(json_file, 'r', encoding='utf-8') as f:
            data = json.load(f)
    except json.JSONDecodeError:
        print(f"Error: {json_file} is not a valid JSON file.")
        sys.exit(1)
    except FileNotFoundError:
        print(f"Error: File {json_file} not found.")
        sys.exit(1)

    extract_attachments(data)
    print("Extraction complete.")

if __name__ == "__main__":
    main()
@ryanschiang ryanschiang self-assigned this Dec 10, 2024
@ryanschiang ryanschiang added the enhancement New feature or request label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants