Skip to content

Commit 3de6b39

Browse files
committed
fix: small changes
1 parent 8775ae3 commit 3de6b39

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

app/internal/import_file.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
from pathlib import Path
55
import re
6-
from typing import Any, Dict, List, Tuple, Union
6+
from typing import Any, Dict, Generator, List, Tuple, Union
77

88
from icalendar import Calendar
99

@@ -18,6 +18,7 @@
1818
)
1919
from app.database.database import SessionLocal
2020
from app.routers.event import create_event
21+
from loguru import logger
2122

2223

2324
DATE_FORMAT = "%m-%d-%Y"
@@ -91,9 +92,10 @@ def is_file_valid_to_save_to_database(events: List[Dict[str, Union[str, Any]]],
9192
return same_date_counter <= max_event_start_date
9293

9394

94-
def open_txt_file(txt_file: str) -> List[str]:
95+
def open_txt_file(txt_file: str) -> Generator[str, None, None]:
9596
with open(txt_file, "r") as text:
96-
return text.readlines()
97+
for row in text.readlines():
98+
yield row
9799

98100

99101
def save_calendar_content_txt(event: str, calendar_content: List) -> bool:
@@ -114,8 +116,7 @@ def save_calendar_content_txt(event: str, calendar_content: List) -> bool:
114116

115117
def import_txt_file(txt_file: str) -> List[Dict[str, Union[str, Any]]]:
116118
calendar_content = []
117-
events = open_txt_file(txt_file)
118-
for event in events:
119+
for event in open_txt_file(txt_file):
119120
if (not is_event_text_valid(event) or
120121
not save_calendar_content_txt(event, calendar_content)):
121122
return []
@@ -126,7 +127,8 @@ def open_ics(ics_file: str) -> Union[List, Calendar]:
126127
with open(ics_file, "r") as ics:
127128
try:
128129
calendar_read = Calendar.from_ical(ics.read())
129-
except (IndexError, ValueError):
130+
except (IndexError, ValueError) as e:
131+
logger.error(f"open_ics function failed error message: {e}")
130132
return []
131133
return calendar_read
132134

0 commit comments

Comments
 (0)