From 6b828ccd6f85fb333b355b501385ad235d53af7e Mon Sep 17 00:00:00 2001 From: Steve Severance Date: Tue, 19 May 2020 10:45:40 -0400 Subject: [PATCH 1/2] make path configurable --- IEXTools/IEXDownloader.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/IEXTools/IEXDownloader.py b/IEXTools/IEXDownloader.py index 6b67664..a0f5ccc 100644 --- a/IEXTools/IEXDownloader.py +++ b/IEXTools/IEXDownloader.py @@ -17,19 +17,19 @@ class DataDownloader(object): - def __init__(self) -> None: + def __init__(self, path: str = None) -> None: """ Initiate the class with the IEX API endpoint information and initializes the folder to put the downloaded data into. """ self.base_endpoint = "https://api.iextrading.com/1.0/" - if sys.argv[0]: - os.chdir(os.path.dirname(sys.argv[0])) - - self.directory = "IEX_data" - if not os.path.exists(self.directory): - os.makedirs(self.directory) + if path: + self.directory = path + else: + self.directory = "IEX_data" + if not os.path.exists(self.directory): + os.makedirs(self.directory) def _get_endpoint(self, date: datetime) -> str: """ From 43adba29b3747bbee391df961b7af935252f8919 Mon Sep 17 00:00:00 2001 From: Steve Severance Date: Fri, 22 May 2020 11:38:16 -0400 Subject: [PATCH 2/2] add support for gzip pcap files --- IEXTools/IEXparser.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/IEXTools/IEXparser.py b/IEXTools/IEXparser.py index 0734673..fd26ff7 100644 --- a/IEXTools/IEXparser.py +++ b/IEXTools/IEXparser.py @@ -35,8 +35,9 @@ ''' """ from __future__ import annotations -import struct from datetime import datetime, timezone +import gzip +import struct from . import messages from typing import BinaryIO, Optional, Iterator, Union, List, Tuple, Dict from .IEXHISTExceptions import ProtocolException @@ -133,7 +134,10 @@ def _load(self, file_path: str) -> BinaryIO: Function to load a TOPS File into the parser. Simply returns a file object which other methods will iterate over. """ - return open(file_path, "rb") + if file_path.endswith('.gz'): + return gzip.open(file_path, "rb") + else: + return open(file_path, "rb") def _get_session_id(self, file_path: str) -> bytes: """ @@ -154,7 +158,7 @@ def _get_session_id(self, file_path: str) -> bytes: iex_header_start = ( self.version + self.reserved + self.protocol_id + self.channel_id ) - with open(file_path, "rb") as market_file: + with self._load(file_path) as market_file: found = False i = 0 while not found: