import json
import os
import time
import hashlib
from services import pastie, dpaste, rentry, defau, sprunge, opendev
from data import data

def save(data):
    # Upload to the available services
    paste_dict = {'name': name}
    successes = []
    failures = []
    for service in [defau]:
        try:
            result = service.upload(data)
            add_data(result["service"], result["key"], result["md5sum"] )
            successes.append(result['name'])
        except Exception as e:
            failures.append(f"{service.__name__}: {str(e)}")

# Print upload results
print(f"Upload successful to {len(successes)}/{len(successes)+len(failures)} services:")
for name in successes:
    print(f"- {name}")
if failures:
    print("Upload failed to the following services:")
    for error in failures:
        print(f"- {error}")

print(f"Your paste trace is: {name}")
