66import csv
77import gzip
88import logging
9- import os
109from datetime import datetime , timedelta
1110from io import StringIO
1211from pathlib import Path
@@ -34,8 +33,8 @@ def __init__(self, error_mode=ErrorMode.TruncTrace):
3433 self .error_mode = error_mode
3534 self .cachedir = self .CACHEDIR
3635 self .backup_cachedir = self .BACKUPCACHEDIR
37- self .epss_path = str ( Path ( self .cachedir ) / "epss" )
38- self .file_name = os . path . join ( self .epss_path , "epss_scores-current.csv" )
36+ self .epss_path = self .cachedir / "epss"
37+ self .file_name = self .epss_path / "epss_scores-current.csv"
3938 self .source_name = self .SOURCE
4039
4140 async def update_epss (self ):
@@ -58,11 +57,11 @@ async def download_epss_data(self):
5857 """Downloads the EPSS CSV file and saves it to the local filesystem.
5958 The download is only performed if the file is older than 24 hours.
6059 """
61- os . makedirs ( self .epss_path , exist_ok = True )
60+ self .epss_path . mkdir ( parents = True , exist_ok = True )
6261 # Check if the file exists
63- if os . path .exists (self . file_name ):
62+ if self . file_name .exists ():
6463 # Get the modification time of the file
65- modified_time = os . path . getmtime ( self .file_name )
64+ modified_time = self .file_name . stat (). st_mtime
6665 last_modified = datetime .fromtimestamp (modified_time )
6766
6867 # Calculate the time difference between now and the last modified time
@@ -80,8 +79,7 @@ async def download_epss_data(self):
8079 decompressed_data = gzip .decompress (await response .read ())
8180
8281 # Save the downloaded data to the file
83- with open (self .file_name , "wb" ) as file :
84- file .write (decompressed_data )
82+ self .file_name .write_bytes (decompressed_data )
8583
8684 except aiohttp .ClientError as e :
8785 self .LOGGER .error (f"An error occurred during updating epss { e } " )
@@ -102,8 +100,7 @@ async def download_epss_data(self):
102100 decompressed_data = gzip .decompress (await response .read ())
103101
104102 # Save the downloaded data to the file
105- with open (self .file_name , "wb" ) as file :
106- file .write (decompressed_data )
103+ self .file_name .write_bytes (decompressed_data )
107104
108105 except aiohttp .ClientError as e :
109106 self .LOGGER .error (f"An error occurred during downloading epss { e } " )
@@ -114,9 +111,8 @@ def parse_epss_data(self, file_path=None):
114111 if file_path is None :
115112 file_path = self .file_name
116113
117- with open (file_path ) as file :
118- # Read the content of the CSV file
119- decoded_data = file .read ()
114+ # Read the content of the CSV file
115+ decoded_data = Path (file_path ).read_text ()
120116
121117 # Create a CSV reader to read the data from the decoded CSV content
122118 reader = csv .reader (StringIO (decoded_data ), delimiter = "," )
0 commit comments