-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.py
More file actions
63 lines (50 loc) · 2.7 KB
/
template.py
File metadata and controls
63 lines (50 loc) · 2.7 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
import os
from pathlib import Path
import re
# Below is the list of all files and directories that I have created for this assignment, as explained for the recruiter.
list_of_files = [
# The StopWords directory and its files, included as per assignment requirements (explained for recruiter)
"StopWords/StopWords_Auditor.txt",
"StopWords/StopWords_Currencies.txt",
"StopWords/StopWords_DatesandNumbers.txt",
"StopWords/StopWords_Generic.txt",
"StopWords/StopWords_GenericLong.txt",
"StopWords/StopWords_Geographic.txt",
"StopWords/StopWords_Names.txt",
# The MasterDictionary directory and its files, included for sentiment analysis (explained for recruiter)
"MasterDictionary/positive-words.txt",
"MasterDictionary/negative-words.txt",
# Files in the root directory, necessary for input, output, main script, requirements, and instructions (explained for recruiter)
"Input.xlsx",
"output.xlsx",
"main.py",
"requirements.txt",
"instructions.md",
]
# For the Scraped_Articles folder, I am generating files from 37.0.txt to 150.0.txt, as required in the assignment (explained for recruiter)
# There are 114 articles in total, corresponding to URL_IDs 37 to 150.
for i in range(37, 151):
# Format the file path for each article (explained for recruiter)
article_path = f"Blackcoffer_Assignment/Scraped_Articles/{i}.0.txt"
# Add the file path to the main list (explained for recruiter)
list_of_files.append(article_path)
# Loop through each file path in the list (explained for recruiter)
for filepath_str in list_of_files:
# Convert the string path to a Path object for OS compatibility (explained for recruiter)
filepath = Path(filepath_str)
# Split the path into its directory and file name components (explained for recruiter)
filedir, filename = os.path.split(filepath)
# If the directory part is not empty, create the directory (explained for recruiter)
if filedir != "":
os.makedirs(filedir, exist_ok=True)
# I have removed the print statement to keep the output clean (explained for recruiter)
# Check if the file does not exist or is an empty file (explained for recruiter)
if not os.path.exists(filepath) or os.path.getsize(filepath) == 0:
# Create an empty file (explained for recruiter)
with open(filepath, 'w') as f:
pass # 'pass' does nothing, it just ensures the file is created (explained for recruiter)
print(f"Creating empty file: {filepath}")
# If the file already exists and is not empty, print a message (explained for recruiter)
else:
print(f"File '{filename}' already exists.")
print("\nBlackcoffer project structure created successfully! ✅")