iozxv commited on
Commit
eb81349
·
verified ·
1 Parent(s): 2525df9

Update sync.py

Browse files
Files changed (1) hide show
  1. sync.py +13 -7
sync.py CHANGED
@@ -7,9 +7,9 @@ from urllib.parse import urljoin, unquote
7
  from huggingface_hub import HfApi
8
 
9
  # Configuration from Environment Variables (Secrets)
10
- ONION_URL = os.getenv("ONION_URL") # e.g., http://xyz.onion/dirname/
11
  HF_TOKEN = os.getenv("HF_TOKEN")
12
- DATASET_REPO_ID = os.getenv("DATASET_REPO_ID") # e.g., username/dataset-name
13
 
14
  HISTORY_FILE = "history.json"
15
  MAX_LOCAL_STORAGE_BYTES = 35 * 1024 * 1024 * 1024 # Keep below 40GB limit (35GB threshold)
@@ -55,15 +55,18 @@ def crawl_and_collect(url, relative_path=""):
55
  soup = BeautifulSoup(response.text, 'html.parser')
56
  for link in soup.find_all('a'):
57
  href = link.get('href')
58
- if not href or href.startswith('?') or href == '../' or href == './':
59
  continue
60
 
61
- clean_href = unquote(href)
 
 
 
62
  full_url = urljoin(url, href)
63
  target_rel_path = os.path.join(relative_path, clean_href)
64
 
65
- if href.endswith('/'):
66
- # Recursive call for subdirectories
67
  files_to_download.extend(crawl_and_collect(full_url, target_rel_path))
68
  else:
69
  files_to_download.append((full_url, target_rel_path))
@@ -80,7 +83,10 @@ def main():
80
  api = HfApi(token=HF_TOKEN)
81
  completed_files = load_history()
82
 
83
- print("Discovering file structure from .onion source...")
 
 
 
84
  all_files = crawl_and_collect(ONION_URL)
85
  print(f"Total files discovered: {len(all_files)}")
86
 
 
7
  from huggingface_hub import HfApi
8
 
9
  # Configuration from Environment Variables (Secrets)
10
+ ONION_URL = os.getenv("ONION_URL") # Must be: http://6qqz6m3b6htudohg2mlf5gdcalonxy3sh5g4dix4mpyirjcgelqqufad.onion/bankofbaroda.bank.in/
11
  HF_TOKEN = os.getenv("HF_TOKEN")
12
+ DATASET_REPO_ID = os.getenv("DATASET_REPO_ID") # username/dataset-name
13
 
14
  HISTORY_FILE = "history.json"
15
  MAX_LOCAL_STORAGE_BYTES = 35 * 1024 * 1024 * 1024 # Keep below 40GB limit (35GB threshold)
 
55
  soup = BeautifulSoup(response.text, 'html.parser')
56
  for link in soup.find_all('a'):
57
  href = link.get('href')
58
+ if not href or href.startswith('?') or href in ['../', './', '..', '.']:
59
  continue
60
 
61
+ clean_href = unquote(href).strip('/')
62
+ if not clean_href:
63
+ continue
64
+
65
  full_url = urljoin(url, href)
66
  target_rel_path = os.path.join(relative_path, clean_href)
67
 
68
+ # Check if it's a directory (ends with / in href or has trailing slash)
69
+ if href.endswith('/') or link.text.endswith('/'):
70
  files_to_download.extend(crawl_and_collect(full_url, target_rel_path))
71
  else:
72
  files_to_download.append((full_url, target_rel_path))
 
83
  api = HfApi(token=HF_TOKEN)
84
  completed_files = load_history()
85
 
86
+ print("Waiting for Tor circuits to finalize...")
87
+ time.sleep(10)
88
+
89
+ print("Discovering file structure from .onion root source...")
90
  all_files = crawl_and_collect(ONION_URL)
91
  print(f"Total files discovered: {len(all_files)}")
92