-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileoperations.py
More file actions
88 lines (68 loc) · 2.68 KB
/
Copy pathfileoperations.py
File metadata and controls
88 lines (68 loc) · 2.68 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
import os
from author import Author
from author_of import Author_of
from publisher import Publisher
from book import Book
class FileOperations:
@staticmethod
def create_file_writer(path):
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
file_writer = open(path, "w")
return file_writer
@staticmethod
def read_author_file(path_to_file):
author_list = []
try:
with open(path_to_file, "r") as file_reader:
for line in file_reader:
words = line.strip().split("\t")
if len(words) >= 2:
author_list.append(Author(int(words[0]), words[1]))
else:
print("There is a problem in Author File Reading phase")
except IOError as e:
print("Error reading file:", e)
return author_list
@staticmethod
def read_publisher_file(path_to_file):
publisher_list = []
try:
with open(path_to_file, "r") as file_reader:
for line in file_reader:
words = line.strip().split("\t")
if len(words) >= 2:
publisher_list.append(Publisher(int(words[0]), words[1]))
else:
print("There is a problem in Publisher File Reading phase")
except IOError as e:
print("Error reading file:", e)
return publisher_list
@staticmethod
def read_book_file(path_to_file):
book_list = []
try:
with open(path_to_file, "r") as file_reader:
for line in file_reader:
words = line.strip().split("\t")
if len(words) >= 7:
book_list.append(Book(words[0], words[1], int(words[2]), words[3], int(words[4]), words[5], float(words[6])))
else:
print("There is a problem in Book File Reading phase")
except IOError as e:
print("Error reading file:", e)
return book_list
@staticmethod
def read_author_of_file(path_to_file):
author_of_list = []
try:
with open(path_to_file, "r") as file_reader:
for line in file_reader:
words = line.strip().split("\t")
if len(words) >= 2:
author_of_list.append(Author_of(words[0], int(words[1])))
else:
print("There is a problem in Author_of File Reading phase")
except IOError as e:
print("Error reading file:", e)
return author_of_list