function find_invoice_uuid
Searches through all documents in a Remarkable cloud storage account to find documents with 'invoice' in their name and prints their UUIDs.
/tf/active/vicechatdev/e-ink-llm/cloudtest/find_invoice_uuid.py
11 - 69
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
jsonrequestsauth
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
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_invoice_pagedata 70.1% similar
-
function verify_document_status 56.0% similar
-
function main_v83 55.6% similar
-
function analyze_trash_indicators 55.1% similar
-
function show_current_root 54.4% similar