šŸ” Code Extractor

function verify_document_status

Maturity: 46

Verifies the current status and metadata of a specific test document in the reMarkable cloud sync system by querying the sync API endpoints and analyzing the document's location and properties.

File:
/tf/active/vicechatdev/e-ink-llm/cloudtest/verify_document_status.py
Lines:
13 - 153
Complexity:
complex

Purpose

This diagnostic function performs a comprehensive check of a hardcoded test document (UUID: 206f5df3-07c2-4341-8afd-2b7362aefa91) in the reMarkable cloud storage. It retrieves the root document schema, locates the target document, fetches its metadata, and analyzes its current folder location (root, trash, or gpt_in folder). The function is designed for debugging and verification purposes to ensure documents are properly synced and located in the expected folders within the reMarkable ecosystem.

Source Code

def verify_document_status():
    """Check current status of the test document"""
    
    # Load auth session
    auth = RemarkableAuth()
    session = auth.get_authenticated_session()
    
    if not session:
        print("āŒ Failed to authenticate")
        return False
    
    print("šŸ” Verifying Current Document Status")
    print("=" * 50)
    
    target_doc_uuid = "206f5df3-07c2-4341-8afd-2b7362aefa91"
    
    try:
        # Step 1: Get current root.docSchema
        print("\nšŸ“‹ Step 1: Getting current root.docSchema from server...")
        root_response = session.get("https://eu.tectonic.remarkable.com/sync/v4/root")
        root_response.raise_for_status()
        root_data = root_response.json()
        
        print(f"āœ… Current root hash: {root_data['hash']}")
        print(f"āœ… Current generation: {root_data.get('generation')}")
        
        # Step 2: Get root content
        print(f"\nšŸ“‹ Step 2: Fetching root.docSchema content...")
        root_content_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{root_data['hash']}")
        root_content_response.raise_for_status()  
        root_content = root_content_response.text
        
        print(f"āœ… Root.docSchema size: {len(root_content)} bytes")
        
        # Step 3: Find our document
        print(f"\nšŸ“„ Step 3: Looking for document {target_doc_uuid[:8]}... in root.docSchema")
        
        doc_entry = None
        doc_hash = None
        
        for line in root_content.strip().split('\n')[1:]:  # Skip version
            if target_doc_uuid in line:
                doc_entry = line
                parts = line.split(':')
                if len(parts) >= 5:
                    doc_hash = parts[0]
                break
        
        if not doc_entry:
            print(f"āŒ Document {target_doc_uuid} NOT found in root.docSchema")
            print(f"šŸ“„ Current root.docSchema content:")
            for i, line in enumerate(root_content.strip().split('\n')):
                print(f"   {i}: {line}")
            return False
        
        print(f"āœ… Found document entry: {doc_entry}")
        print(f"āœ… Document hash: {doc_hash}")
        
        # Step 4: Get document's current docSchema
        print(f"\nšŸ“„ Step 4: Fetching document's docSchema...")
        doc_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{doc_hash}")
        doc_response.raise_for_status()
        doc_content = doc_response.text
        
        print(f"āœ… Document docSchema size: {len(doc_content)} bytes")
        print(f"šŸ“„ Document docSchema content:")
        
        doc_lines = doc_content.strip().split('\n')
        for i, line in enumerate(doc_lines):
            print(f"   {i}: {line}")
        
        # Step 5: Get current metadata
        print(f"\nšŸ“ Step 5: Getting current metadata...")
        
        metadata_hash = None
        for line in doc_lines[1:]:  # Skip version
            if ':' in line and '.metadata' in line:
                parts = line.split(':')
                if len(parts) >= 5:
                    metadata_hash = parts[0]
                    break
        
        if not metadata_hash:
            print(f"āŒ Metadata component not found")
            return False
        
        print(f"āœ… Metadata hash: {metadata_hash}")
        
        # Fetch current metadata
        metadata_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{metadata_hash}")
        metadata_response.raise_for_status()
        current_metadata = json.loads(metadata_response.text)
        
        print(f"\nšŸ“Š CURRENT METADATA:")
        print(f"   Document Name: {current_metadata.get('visibleName', 'N/A')}")
        print(f"   Parent UUID: {current_metadata.get('parent', 'N/A')}")
        print(f"   Parent Display: {'(root)' if current_metadata.get('parent', '') == '' else current_metadata.get('parent', 'N/A')}")
        print(f"   Document Type: {current_metadata.get('type', 'N/A')}")
        print(f"   Last Modified: {current_metadata.get('lastModified', 'N/A')}")
        print(f"   Created Time: {current_metadata.get('createdTime', 'N/A')}")
        print(f"   Deleted: {current_metadata.get('deleted', 'N/A')}")
        print(f"   Pinned: {current_metadata.get('pinned', 'N/A')}")
        
        print(f"\nšŸ“„ FULL METADATA JSON:")
        print(json.dumps(current_metadata, indent=2))
        
        # Step 6: Check if gpt_in folder exists and its UUID
        print(f"\nšŸ“ Step 6: Checking gpt_in folder status...")
        gpt_in_uuid = "99c6551f-2855-44cf-a4e4-c9c586558f42"
        
        gpt_in_found = False
        for line in root_content.strip().split('\n')[1:]:
            if gpt_in_uuid in line:
                gpt_in_found = True
                print(f"āœ… Found gpt_in folder: {line}")
                break
        
        if not gpt_in_found:
            print(f"āŒ gpt_in folder ({gpt_in_uuid}) not found in root.docSchema")
        
        # Step 7: Analysis
        print(f"\nšŸ” ANALYSIS:")
        parent = current_metadata.get('parent', '')
        if parent == '':
            print(f"šŸ“Š Document is currently in ROOT folder")
        elif parent == 'trash':
            print(f"šŸ“Š Document is currently in TRASH")
        elif parent == gpt_in_uuid:
            print(f"šŸ“Š Document is currently in GPT_IN folder")
        else:
            print(f"šŸ“Š Document is in UNKNOWN folder: {parent}")
        
        print(f"šŸ“Š Expected gpt_in UUID: {gpt_in_uuid}")
        print(f"šŸ“Š Actual parent UUID: {parent}")
        print(f"šŸ“Š Match: {'āœ… YES' if parent == gpt_in_uuid else 'āŒ NO'}")
        
        return True
        
    except Exception as e:
        print(f"āŒ Verification failed: {e}")
        return False

Return Value

Returns a boolean value: True if the verification process completes successfully (document found and all data retrieved), False if authentication fails, the document is not found, or any error occurs during the verification process. The function primarily outputs diagnostic information to stdout rather than returning structured data.

Dependencies

  • json
  • requests
  • auth

Required Imports

import json
import requests
from auth import RemarkableAuth

Usage Example

# Ensure auth.py module is available with RemarkableAuth class
# The function uses hardcoded document UUID and folder UUID

from verify_document_status import verify_document_status

# Run verification - outputs detailed status to console
success = verify_document_status()

if success:
    print("Verification completed successfully")
else:
    print("Verification failed - check console output for details")

Best Practices

  • This function is hardcoded for a specific test document UUID (206f5df3-07c2-4341-8afd-2b7362aefa91) and should be modified to accept document UUID as a parameter for general use
  • The function makes multiple sequential API calls which could be optimized or made concurrent for better performance
  • Error handling could be improved to provide more specific error messages for different failure scenarios
  • The function outputs directly to stdout using print statements - consider using logging module for production use
  • The gpt_in folder UUID (99c6551f-2855-44cf-a4e4-c9c586558f42) is hardcoded and should be configurable
  • Consider adding retry logic for API calls to handle transient network failures
  • The function assumes the reMarkable API structure and endpoints remain stable - may need updates if API changes
  • Authentication session should be properly closed or managed in a context manager to prevent resource leaks

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function check_gpt_in_folder 73.0% similar

    Diagnostic function that checks the status, metadata, and contents of a specific 'gpt_in' folder in the reMarkable cloud storage system, providing detailed analysis of folder structure and potential sync issues.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/check_gpt_in_folder.py
  • function verify_cloud_empty 72.3% similar

    Verifies that a reMarkable cloud storage account is completely empty by authenticating, retrieving the root document schema, and analyzing its contents for any remaining documents or folders.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/verify_cloud_empty.py
  • function main_v6 71.1% similar

    Integration test function that validates the fixed upload implementation for reMarkable cloud sync by creating a test PDF document, uploading it with corrected metadata patterns, and verifying its successful appearance in the reMarkable ecosystem.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/test_fixed_upload.py
  • function main_v15 70.8% similar

    A test function that uploads a PDF document to reMarkable cloud, syncs the local replica, and validates the upload with detailed logging and metrics.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/test_raw_upload.py
  • function main_v113 70.1% similar

    Analyzes and compares .content files for PDF documents stored in reMarkable cloud storage, identifying differences between working and non-working documents.

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