File size: 1,280 Bytes
3277f6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66a71a2
 
 
 
 
3277f6f
 
 
 
 
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
import os

# Base URL for the links
base_url = "https://huggingface.co/datasets/rulins/raw_data/resolve/main"

# List to store the generated URLs
urls = []

# Walk through the directory
for root, dirs, files in os.walk('.'):
    for file in files:
        if file.endswith('.jsonl'):
            # Get the relative path
            relative_path = os.path.relpath(os.path.join(root, file), '.')
            # Replace backslashes with forward slashes for URLs
            relative_path = relative_path.replace(os.sep, '/')
            # Generate the URL
            url = f"{base_url}/{relative_path}?download=true"
            urls.append((url, relative_path))

# Create a bash script
with open('download_files.sh', 'w') as bash_script:
    bash_script.write("#!/bin/bash\n\n")
    for url, relative_path in urls:
        # Extract directory path
        dir_path = os.path.dirname(relative_path)
        # Add command to create directory if it doesn't exist
        if dir_path:
            bash_script.write(f"mkdir -p \"{dir_path}\"\n")
        bash_script.write(f"if [ ! -f \"{relative_path}\" ]; then\n")
        bash_script.write(f"    wget -O \"{relative_path}\" \"{url}\"\n")
        bash_script.write("fi\n\n")

print("Bash script 'download_files.sh' has been created.")