File size: 1,885 Bytes
1637cd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""
Test downloading files from URLs
"""

import requests
import pandas as pd
import PyPDF2
from io import BytesIO

def test_file_download():
    """Test downloading different file types from URLs"""
    
    # Example URLs (these are hypothetical)
    test_urls = [
        {
            "url": "https://example.com/sales_data.xlsx",
            "type": "excel",
            "question": "What is the total sales from the Excel file at https://example.com/sales_data.xlsx?"
        },
        {
            "url": "https://example.com/document.pdf", 
            "type": "pdf",
            "question": "How many times does 'therefore' appear in https://example.com/document.pdf?"
        }
    ]
    
    for test in test_urls:
        print(f"\nTesting {test['type']} download:")
        print(f"URL: {test['url']}")
        
        try:
            # Download the file
            response = requests.get(test['url'], timeout=10)
            
            if response.status_code == 200:
                print("βœ… File downloaded successfully")
                
                # Process based on file type
                if test['type'] == 'excel':
                    # Read Excel file
                    df = pd.read_excel(BytesIO(response.content))
                    print(f"Excel shape: {df.shape}")
                    print(f"Columns: {list(df.columns)}")
                    
                elif test['type'] == 'pdf':
                    # Read PDF file
                    pdf_reader = PyPDF2.PdfReader(BytesIO(response.content))
                    print(f"PDF pages: {len(pdf_reader.pages)}")
                    
            else:
                print(f"❌ Failed to download: {response.status_code}")
                
        except Exception as e:
            print(f"❌ Error: {e}")

if __name__ == "__main__":
    test_file_download()