šŸ” Code Extractor

function find_invoice_uuid

Maturity: 46

Searches through all documents in a Remarkable cloud storage account to find documents with 'invoice' in their name and prints their UUIDs.

File:
/tf/active/vicechatdev/e-ink-llm/cloudtest/find_invoice_uuid.py
Lines:
11 - 69
Complexity:
complex

Purpose

This function authenticates with the Remarkable cloud API, retrieves the root document schema, iterates through all documents to fetch their metadata, and identifies documents containing 'invoice' in their visible name. It's designed for debugging or discovery purposes to locate invoice documents within a Remarkable account's document hierarchy.

Source Code

def find_invoice_uuid():
    """Find the invoice document UUID"""
    auth = RemarkableAuth()
    session = auth.get_authenticated_session()
    
    if not session:
        raise RuntimeError("Failed to authenticate")
    
    # Get root info
    root_response = session.get("https://eu.tectonic.remarkable.com/sync/v4/root")
    root_response.raise_for_status()
    root_data = root_response.json()
    
    # Get root 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("šŸ“‹ All documents in root.docSchema:")
    lines = root_content.strip().split('\n')
    
    for line in lines[1:]:  # Skip version header
        if ':' in line:
            parts = line.split(':')
            if len(parts) >= 5:
                doc_hash = parts[0]
                doc_uuid = parts[2]
                
                # Get document metadata to check name
                try:
                    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
                    doc_lines = doc_content.strip().split('\n')
                    
                    # Find metadata
                    for doc_line in doc_lines[1:]:
                        if ':' in doc_line and '.metadata' in doc_line:
                            metadata_parts = doc_line.split(':')
                            if len(metadata_parts) >= 5:
                                metadata_hash = metadata_parts[0]
                                metadata_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{metadata_hash}")
                                metadata_response.raise_for_status()
                                metadata = json.loads(metadata_response.text)
                                
                                doc_name = metadata.get('visibleName', 'Unknown')
                                print(f"   {doc_name}: {doc_uuid}")
                                
                                if 'invoice' in doc_name.lower():
                                    print(f"šŸŽÆ FOUND INVOICE: {doc_name} -> {doc_uuid}")
                                break
                            break
                
                except Exception as e:
                    print(f"   Error checking {doc_uuid[:8]}...: {e}")
                    continue
    
    print("\nšŸ“‹ Summary of invoices found:")
    return None

Return Value

Returns None. The function's primary purpose is to print information to stdout, including all document names with their UUIDs and specifically highlighting any documents with 'invoice' in the name. Despite the docstring suggesting it finds invoice UUIDs, it does not return them.

Dependencies

  • json
  • requests
  • auth

Required Imports

import json
from auth import RemarkableAuth

Usage Example

from auth import RemarkableAuth
import json

# Ensure RemarkableAuth is properly configured with credentials
try:
    find_invoice_uuid()
    # Function will print all documents and highlight invoices
    # Example output:
    # šŸ“‹ All documents in root.docSchema:
    #    My Document: abc123-def456-...
    #    Invoice_2024: xyz789-uvw012-...
    # šŸŽÆ FOUND INVOICE: Invoice_2024 -> xyz789-uvw012-...
except RuntimeError as e:
    print(f"Authentication failed: {e}")
except Exception as e:
    print(f"Error finding invoices: {e}")

Best Practices

  • This function has no return value despite its name suggesting it should return a UUID - consider refactoring to return found invoice UUIDs as a list
  • Error handling is minimal - failed document retrievals are caught but continue silently, which may hide issues
  • The function makes multiple synchronous HTTP requests which could be slow for accounts with many documents - consider implementing pagination or async requests
  • Hardcoded API endpoint (eu.tectonic.remarkable.com) may not work for all regions
  • The function prints directly to stdout - consider using logging module for better control over output
  • No caching mechanism - repeated calls will make the same API requests
  • The document schema parsing is fragile and depends on specific format with colon-separated values
  • Consider adding parameters to filter by document name pattern or return structured data instead of printing

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_invoice_pagedata 70.1% similar

    Retrieves pagedata content from a specific Poulpharm invoice document stored in the Remarkable cloud service by authenticating, navigating the document hierarchy, and extracting the pagedata component.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/extract_invoice_pagedata.py
  • function verify_document_status 56.0% similar

    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.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/verify_document_status.py
  • function main_v83 55.6% similar

    A standalone function that forces a refresh of document visibility for a specific hardcoded Remarkable document UUID by instantiating a DocumentRefresher and calling its force_refresh_document method.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/force_web_app_refresh.py
  • function analyze_trash_indicators 55.1% similar

    Analyzes trash indicators in Remarkable Cloud document schemas by comparing documents that were moved to trash versus those that weren't, examining their hash changes and metadata components.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/analyze_trash_indicators.py
  • function show_current_root 54.4% similar

    Fetches and displays the current root.docSchema from the reMarkable cloud sync service, showing metadata and analyzing document entries.

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