-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqp_downloader.py
More file actions
138 lines (113 loc) · 5.09 KB
/
qp_downloader.py
File metadata and controls
138 lines (113 loc) · 5.09 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
"""
IGNOU Question Paper Downloader
Main entry point for downloading IGNOU question papers
"""
import os
import re
import sys
import urllib3
from download import *
# Disable SSL warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def print_banner():
"""Print the application banner"""
banner = """
╔══════════════════════════════════════════════════════════════════════════════╗
║ IGNOU QUESTION PAPER DOWNLOADER ║
║ Download previous years question papers for ║
║ IGNOU BCA/MCA courses ║
║ ║
║ Created by Samiran Kakoty ║
║ Source: https://github.com/samirank/qp_downloader ║
╚══════════════════════════════════════════════════════════════════════════════╝
"""
print(banner)
def clear_screen():
"""Clear the terminal screen cross-platform"""
os.system('cls' if os.name == 'nt' else 'clear')
def main():
"""Main function"""
clear_screen()
print_banner()
try:
# Get course codes from user
print("Enter course code(s) (separate multiple codes with spaces):")
print("Example: BCA-001 BCA-002 MCA-001")
course_input = input("Course codes: ").strip()
if not course_input:
print("Error: No course codes provided!")
sys.exit(1)
course_code = course_input.split()
# Get merge preference
merge_list = []
if len(course_code) == 1:
while True:
choice = input(f'\nDo you want to merge all {course_code[0]} files? (y/n): ').lower()
if choice in ['y', 'yes']:
merge_list = course_code
break
elif choice in ['n', 'no']:
break
else:
print("Please enter 'y' or 'n'")
else:
while True:
choice = input('\nDo you want to merge downloaded files of same course? (y/n): ').lower()
if choice in ['y', 'yes']:
print("\nEnter course codes to merge (separate with spaces)")
print("Or enter 'all' to select all courses")
merge_input = input("Courses to merge: ").strip()
if merge_input.lower() == 'all':
merge_list = course_code
else:
merge_list = merge_input.split()
break
elif choice in ['n', 'no']:
break
else:
print("Please enter 'y' or 'n'")
# Initialize download process
print("\n" + "="*60)
print("Starting download process...")
print("="*60)
# Get HTML content from IGNOU website
url = 'https://webservices.ignou.ac.in/Pre-Question/'
soup = get_html(url)
if isinstance(soup, int):
print(f"Error: {print_error(soup)}")
sys.exit(1)
# Get session links
session_list = get_sessions(soup, url)
if not session_list:
print("Error: No session links found!")
sys.exit(1)
# Get program links
program_links = get_prog_links('SOCIS', session_list)
if not program_links:
print("Error: No program links found!")
sys.exit(1)
# Download files for each course
for current_course in course_code:
print(f"\nProcessing course: {current_course}")
course_links = get_course_link(current_course, program_links)
if course_links:
local_file_path = download_files(course_links, current_course)
# Merge files if requested
for val in merge_list:
if re.match(current_course, val, re.IGNORECASE):
merge(local_file_path, current_course)
break
else:
print(f"No files found for course: {current_course}")
print("\n" + "="*60)
print("Download process completed!")
print("="*60)
except KeyboardInterrupt:
print("\n\nDownload interrupted by user.")
sys.exit(0)
except Exception as e:
print(f"\nAn error occurred: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()