businesslawrag / src /downloader.py
veltrixcode's picture
Upload 54 files
c49440d verified
Raw History Blame Contribute Delete
7.29 kB
import os
import requests
from typing import List, Dict
ICAI_MANIFEST: List[Dict[str, str]] = [
{
"filename": "00_initial_pages.pdf",
"title": "Initial Pages & Syllabus",
"chapter": "Prelims",
"url": "https://resource.cdn.icai.org/88016bos-aps2231-ip.pdf"
},
{
"filename": "01_ch1_indian_regulatory_framework.pdf",
"title": "Chapter 1: Indian Regulatory Framework",
"chapter": "Chapter 1",
"url": "https://resource.cdn.icai.org/88015bos-aps2231-ch1.pdf"
},
{
"filename": "02_ch2_u1_nature_of_contracts.pdf",
"title": "Chapter 2 - Unit 1: Nature of Contracts",
"chapter": "Chapter 2: The Indian Contract Act, 1872",
"url": "https://resource.cdn.icai.org/88017bos-aps2231-ch2u1.pdf"
},
{
"filename": "03_ch2_u2_consideration.pdf",
"title": "Chapter 2 - Unit 2: Consideration",
"chapter": "Chapter 2: The Indian Contract Act, 1872",
"url": "https://resource.cdn.icai.org/88018bos-aps2231-ch2u2.pdf"
},
{
"filename": "04_ch2_u3_essential_elements_of_contract.pdf",
"title": "Chapter 2 - Unit 3: Other Essential Elements of a Contract",
"chapter": "Chapter 2: The Indian Contract Act, 1872",
"url": "https://resource.cdn.icai.org/88019bos-aps2231-ch2u3.pdf"
},
{
"filename": "05_ch2_u4_performance_of_contract.pdf",
"title": "Chapter 2 - Unit 4: Performance of Contract",
"chapter": "Chapter 2: The Indian Contract Act, 1872",
"url": "https://resource.cdn.icai.org/88020bos-aps2231-ch2u4.pdf"
},
{
"filename": "06_ch2_u5_breach_of_contract_and_remedies.pdf",
"title": "Chapter 2 - Unit 5: Breach of Contract and its Remedies",
"chapter": "Chapter 2: The Indian Contract Act, 1872",
"url": "https://resource.cdn.icai.org/88021bos-aps2231-ch2u5.pdf"
},
{
"filename": "07_ch2_u6_contingent_and_quasi_contracts.pdf",
"title": "Chapter 2 - Unit 6: Contingent and Quasi Contracts",
"chapter": "Chapter 2: The Indian Contract Act, 1872",
"url": "https://resource.cdn.icai.org/88022bos-aps2231-ch2u6.pdf"
},
{
"filename": "08_ch2_u7_indemnity_and_guarantee.pdf",
"title": "Chapter 2 - Unit 7: Contract of Indemnity and Guarantee",
"chapter": "Chapter 2: The Indian Contract Act, 1872",
"url": "https://resource.cdn.icai.org/88023bos-aps2231-ch2u7.pdf"
},
{
"filename": "09_ch2_u8_bailment_and_pledge.pdf",
"title": "Chapter 2 - Unit 8: Bailment and Pledge",
"chapter": "Chapter 2: The Indian Contract Act, 1872",
"url": "https://resource.cdn.icai.org/88024bos-aps2231-ch2u8.pdf"
},
{
"filename": "10_ch2_u9_agency.pdf",
"title": "Chapter 2 - Unit 9: Agency",
"chapter": "Chapter 2: The Indian Contract Act, 1872",
"url": "https://resource.cdn.icai.org/88025bos-aps2231-ch2u9.pdf"
},
{
"filename": "11_ch3_u1_formation_of_contract_of_sale.pdf",
"title": "Chapter 3 - Unit 1: Formation of the Contract of Sale",
"chapter": "Chapter 3: The Sale of Goods Act, 1930",
"url": "https://resource.cdn.icai.org/88026bos-aps2231-ch3u1.pdf"
},
{
"filename": "12_ch3_u2_conditions_and_warranties.pdf",
"title": "Chapter 3 - Unit 2: Conditions & Warranties",
"chapter": "Chapter 3: The Sale of Goods Act, 1930",
"url": "https://resource.cdn.icai.org/88027bos-aps2231-ch3u2.pdf"
},
{
"filename": "13_ch3_u3_transfer_of_ownership_and_delivery.pdf",
"title": "Chapter 3 - Unit 3: Transfer of Ownership and Delivery of Goods",
"chapter": "Chapter 3: The Sale of Goods Act, 1930",
"url": "https://resource.cdn.icai.org/88028bos-aps2231-ch3u3.pdf"
},
{
"filename": "14_ch3_u4_unpaid_seller.pdf",
"title": "Chapter 3 - Unit 4: Unpaid Seller",
"chapter": "Chapter 3: The Sale of Goods Act, 1930",
"url": "https://resource.cdn.icai.org/88029bos-aps2231-ch3u4.pdf"
},
{
"filename": "15_ch4_u1_nature_of_partnership.pdf",
"title": "Chapter 4 - Unit 1: General Nature of Partnership",
"chapter": "Chapter 4: The Indian Partnership Act, 1932",
"url": "https://resource.cdn.icai.org/88030bos-aps2231-ch4u1.pdf"
},
{
"filename": "16_ch4_u2_relations_of_partners.pdf",
"title": "Chapter 4 - Unit 2: Relations of Partners",
"chapter": "Chapter 4: The Indian Partnership Act, 1932",
"url": "https://resource.cdn.icai.org/88031bos-aps2231-ch4u2.pdf"
},
{
"filename": "17_ch4_u3_registration_and_dissolution.pdf",
"title": "Chapter 4 - Unit 3: Registration and Dissolution of a Firm",
"chapter": "Chapter 4: The Indian Partnership Act, 1932",
"url": "https://resource.cdn.icai.org/88032bos-aps2231-ch4u3.pdf"
},
{
"filename": "18_ch5_limited_liability_partnership.pdf",
"title": "Chapter 5: The Limited Liability Partnership Act, 2008",
"chapter": "Chapter 5: The Limited Liability Partnership Act, 2008",
"url": "https://resource.cdn.icai.org/88033bos-aps2231-ch5.pdf"
},
{
"filename": "19_ch6_the_companies_act_2013.pdf",
"title": "Chapter 6: The Companies Act, 2013",
"chapter": "Chapter 6: The Companies Act, 2013",
"url": "https://resource.cdn.icai.org/88034bos-aps2231-ch6.pdf"
},
{
"filename": "20_ch7_negotiable_instruments_act.pdf",
"title": "Chapter 7: The Negotiable Instruments Act, 1881",
"chapter": "Chapter 7: The Negotiable Instruments Act, 1881",
"url": "https://resource.cdn.icai.org/88035bos-aps2231-ch7.pdf"
}
]
def download_all_books(target_dir: str = "data/books") -> List[Dict[str, str]]:
os.makedirs(target_dir, exist_ok=True)
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
downloaded = []
print(f"Starting download of {len(ICAI_MANIFEST)} ICAI PDF books into {target_dir}...")
for item in ICAI_MANIFEST:
dest_path = os.path.join(target_dir, item["filename"])
if os.path.exists(dest_path) and os.path.getsize(dest_path) > 1000:
print(f"✔ [Already Exists] {item['filename']} ({item['title']})")
downloaded.append({**item, "local_path": dest_path})
continue
print(f"⬇ Downloading: {item['title']} -> {item['filename']}...")
try:
resp = requests.get(item["url"], headers=headers, timeout=30)
resp.raise_for_status()
with open(dest_path, "wb") as f:
f.write(resp.content)
print(f"✔ [Downloaded] {item['filename']} ({len(resp.content) / 1024:.1f} KB)")
downloaded.append({**item, "local_path": dest_path})
except Exception as e:
print(f"❌ Failed to download {item['url']}: {e}")
print(f"\nCompleted download of {len(downloaded)}/{len(ICAI_MANIFEST)} books.")
return downloaded
if __name__ == "__main__":
download_all_books()