-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_script.py
More file actions
130 lines (82 loc) · 3.11 KB
/
source_script.py
File metadata and controls
130 lines (82 loc) · 3.11 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
import os
import pandas as pd
import PyPDF2
from mylib import city_by_states, is_same
all_cities = [x for val in city_by_states.values() for x in val]
all_cities = [x for x in all_cities if len(x)>3]
# Define stub functions to be implemented later
def extract_name(text):
return "Fourth_NAME"
def extract_email(text):
text=text.split()
for word in text:
if '@' in word:
return word
def extract_phone(text):
return "NO_PHONE"
def extract_city(text):
return "NO_CITY"
def extract_experience(text):
return "NO_EXPERIENCE"
def extract_degree(text):
return "NO_DEGREE"
def extract_stream(text):
return "NO_STREAM"
def extract_college(text):
return "NO_COLLEGE"
def extract_graduation_year(text):
return "NO_YEAR"
def extract_pdf_text(file_path):
"""Extracts and returns all text from a PDF file."""
text = ""
try:
with open(file_path, 'rb') as file:
reader = PyPDF2.PdfReader(file)
for page in reader.pages:
page_text = page.extract_text()
if page_text:
text += page_text
except Exception as e:
print(f"Failed to read {file_path}: {e}")
return text
def process_resumes(folder_path="Resumes", excel_path="report_students.xlsx"):
# Ensure resume folder exists
if not os.path.exists(folder_path):
print(f"The folder '{folder_path}' does not exist.")
return
# Load existing data or create new DataFrame
if os.path.exists(excel_path):
output_df = pd.read_excel(excel_path)
else:
columns = [
"Name", "Email ID", "Phone Number", "Current Location",
"Total Experience", "Under Graduation degree",
"UG Specialization", "UG University/institute Name", "UG Graduation year"
]
output_df = pd.DataFrame(columns=columns)
# Process PDF files one by one
for filename in os.listdir(folder_path):
if filename.lower().endswith(".pdf"):
file_path = os.path.join(folder_path, filename)
print(f"Processing: {file_path}")
text = extract_pdf_text(file_path)
# Prepare new row from extracted data
new_row = pd.DataFrame([{
"Name": extract_name(text),
"Email ID": extract_email(text),
"Phone Number": extract_phone(text),
"Current Location": extract_city(text),
"Total Experience": extract_experience(text),
"Under Graduation degree": extract_degree(text),
"UG Specialization": extract_stream(text),
"UG University/institute Name": extract_college(text),
"UG Graduation year": extract_graduation_year(text)
}])
# Append new row to the existing DataFrame
output_df = pd.concat([output_df, new_row], ignore_index=True)
# Save to Excel immediately
output_df.to_excel(excel_path, index=False)
print(f"Data appended for file: {filename}")
# Run the function
if __name__ == "__main__":
process_resumes()