Skip to content

Commit

Permalink
Merge pull request #13 from sseveran/master
Browse files Browse the repository at this point in the history
Make Path Configurable and add Support for GZIP PCAP files
  • Loading branch information
lvfrazao committed May 26, 2020
2 parents a03376b + 43adba2 commit 5f4755f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 7 additions & 7 deletions IEXTools/IEXDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
10 changes: 7 additions & 3 deletions IEXTools/IEXparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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:
Expand Down

0 comments on commit 5f4755f

Please sign in to comment.