šŸ” Code Extractor

function simple_move_to_trash

Maturity: 38

Moves all documents from the reMarkable tablet's root directory to trash by uploading an empty root.docSchema file and updating the roothash.

File:
/tf/active/vicechatdev/e-ink-llm/cloudtest/simple_clean_root.py
Lines:
23 - 104
Complexity:
moderate

Purpose

This function provides a simple way to clean up all remaining documents in the root directory of a reMarkable tablet by effectively moving them to trash. It authenticates with the reMarkable cloud service, retrieves the current root state, identifies all documents present, then uploads an empty root configuration to remove all items from the visible document tree. This is useful for bulk cleanup operations or resetting the tablet's document structure.

Source Code

def simple_move_to_trash():
    print("šŸ—‘ļø  Simple Move to Trash - Clean Remaining Documents")
    print("=" * 60)
    
    # Get auth
    auth = RemarkableAuth()
    user_token = auth.authenticate()
    session = auth.get_authenticated_session()
    
    if not session or not user_token:
        print("āŒ Authentication failed")
        return
    
    # Get current root state
    root_response = session.get('https://eu.tectonic.remarkable.com/sync/v3/files/root.docSchema')
    root_response.raise_for_status()
    root_content = root_response.text
    
    print(f"šŸ“‹ Current root.docSchema:")
    print(f"   Size: {len(root_content)} bytes")
    print(f"   Content: {repr(root_content)}")
    
    # Parse current root content  
    lines = root_content.strip().split('\n')
    print(f"\nšŸ“Š Found {len(lines) - 1} items in root:")
    
    remaining_uuids = []
    for line in lines[1:]:  # Skip version line
        if ':' in line:
            parts = line.split(':')
            if len(parts) >= 3:
                uuid = parts[2]
                remaining_uuids.append(uuid)
                print(f"   šŸ” UUID: {uuid}")
    
    if not remaining_uuids:
        print("šŸŽ‰ Root is already empty!")
        return
    
    print(f"\nšŸ—‘ļø  Moving {len(remaining_uuids)} documents to trash...")
    
    # Create empty root content (just version line)
    empty_root_content = "3\n"
    
    # Upload empty root
    root_crc = calculate_crc32c(empty_root_content)
    root_headers = {
        'Authorization': f'Bearer {user_token}',
        'User-Agent': 'reMarkable-desktop-win/3.11.1.1951',
        'rm-filename': 'root.docSchema',
        'rm-crc32c': root_crc,
        'Content-Type': 'application/octet-stream'
    }
    
    try:
        root_upload_response = session.put(
            'https://eu.tectonic.remarkable.com/sync/v3/files',
            headers=root_headers,
            data=empty_root_content
        )
        root_upload_response.raise_for_status()
        new_root_hash = root_upload_response.text.strip()
        
        print(f"āœ… Empty root uploaded: {new_root_hash[:16]}...")
        
        # Update roothash
        roothash_response = session.put(
            'https://eu.tectonic.remarkable.com/sync/v3/roothash',
            headers={
                'Authorization': f'Bearer {user_token}',
                'User-Agent': 'reMarkable-desktop-win/3.11.1.1951',
                'Content-Type': 'text/plain'
            },
            data=new_root_hash
        )
        roothash_response.raise_for_status()
        
        print(f"āœ… Roothash updated successfully")
        print(f"šŸŽ‰ All documents removed from root - effectively moved to trash!")
        
    except Exception as e:
        print(f"āŒ Error emptying root: {e}")

Return Value

This function does not return any value (implicitly returns None). It performs side effects by modifying the reMarkable cloud state and prints status messages to stdout indicating success or failure of the operation.

Dependencies

  • requests
  • json
  • hashlib
  • base64
  • binascii

Required Imports

from auth import RemarkableAuth
import json
import hashlib
import base64
import binascii

Usage Example

# Ensure auth.py with RemarkableAuth class is available
# Ensure calculate_crc32c function is defined

from auth import RemarkableAuth
import hashlib
import base64
import binascii

def calculate_crc32c(data):
    # Implementation of CRC32C calculation
    crc = binascii.crc32(data.encode('utf-8'))
    return base64.b64encode(crc.to_bytes(4, 'big')).decode('utf-8')

# Call the function to move all documents to trash
simple_move_to_trash()

# Output will show:
# - Current root state
# - List of UUIDs being moved
# - Success/failure messages

Best Practices

  • This function performs destructive operations - all documents in root will be moved to trash
  • Ensure you have backups before running this function as it removes all visible documents
  • The function assumes the EU region endpoint (eu.tectonic.remarkable.com) - may need modification for other regions
  • Error handling is basic - consider adding more robust error recovery for production use
  • The function prints status messages directly - consider using logging for better control in production
  • Authentication credentials should be securely managed by the RemarkableAuth class
  • The calculate_crc32c function must be properly implemented and available in scope
  • Network connectivity to reMarkable cloud services is required
  • The function does not provide an undo mechanism - documents can only be recovered from trash through the reMarkable interface

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function move_documents_to_trash 85.1% similar

    Moves specified reMarkable Cloud documents to trash by updating their metadata parent field to 'trash' and propagating changes through the document hierarchy.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/move_remaining_to_trash_fixed.py
  • function apply_working_trash_move 84.7% similar

    Moves a hardcoded list of reMarkable cloud documents to trash by authenticating with the reMarkable API and applying trash operations to each document.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/apply_working_trash_move.py
  • function move_document_to_trash 84.7% similar

    Moves a reMarkable document to trash by updating its metadata parent field to 'trash', then propagating the changes through the document schema hierarchy and updating the root hash.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/apply_working_trash_move.py
  • class DocumentToTrashMover 82.9% similar

    A class that moves reMarkable documents to the trash by updating their metadata parent field to 'trash' and synchronizing changes through the reMarkable cloud API.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/move_documents_to_trash.py
  • function main_v45 77.7% similar

    Command-line interface function that moves a single reMarkable document to trash by accepting a document UUID as a command-line argument.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/move_documents_to_trash.py
← Back to Browse