mirror of
				https://github.com/sissbruecker/linkding.git
				synced 2025-11-04 13:04:00 +01:00 
			
		
		
		
	* generate fallback web archive URL if none exists * remove fallback web archive snapshot creation * fix test
		
			
				
	
	
		
			21 lines
		
	
	
		
			625 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			625 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import datetime
 | 
						|
 | 
						|
from django.utils import timezone
 | 
						|
 | 
						|
 | 
						|
def generate_fallback_webarchive_url(
 | 
						|
    url: str, timestamp: datetime.datetime
 | 
						|
) -> str | None:
 | 
						|
    """
 | 
						|
    Generate a URL to the web archive for the given URL and timestamp.
 | 
						|
    A snapshot for the specific timestamp might not exist, in which case the
 | 
						|
    web archive will show the closest snapshot to the given timestamp.
 | 
						|
    If there is no snapshot at all the URL will be invalid.
 | 
						|
    """
 | 
						|
    if not url:
 | 
						|
        return None
 | 
						|
    if not timestamp:
 | 
						|
        timestamp = timezone.now()
 | 
						|
 | 
						|
    return f"https://web.archive.org/web/{timestamp.strftime('%Y%m%d%H%M%S')}/{url}"
 |